xhr-mock

Testing an AJAX function with xhr-mock fails

烈酒焚心 提交于 2019-12-24 00:49:27
问题 I'm trying to test the following function from my network.js : export function post (data) { return new Promise(function (resolve, reject) { // need to log to the root var url = window.location.protocol + '//' + window.location.hostname var xhr = new XMLHttpRequest() xhr.onreadystatechange = () => { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 204) { resolve(null) } else { reject(new Error('an error ocurred whilst sending the request')) } } } xhr.open('POST', url, true)