Closed beckend closed 6 years ago
Which version are you using? Are you using xhr-mock@next
(v2
)? Can you please provide a snippet of a minimal example that you'd expect to work.
const xhr = new XMLHttpRequest();
const handleProgress = (evt) => {
console.log(evt);
};
xhr.upload.addEventListener('progress', handleProgress);
xhr.upload.removeEventListener('progress', handleProgress);
using 2.x preview 7
also on the note with this snippet which does not work in xhr-mock, but does in browsers.
xhr.addEventListener('loadend', handleLoadEnd);
if error occurs, this does not fire(it should).
Sorry, can you please include a full example including the mock setup and full xhr details.
It should work according to these tests
the tests looks convincing, makes me wonder if i did something weird, will get back to this coming days.
Hi @beckend. Have you managed to figure out whats going wrong?
@jameslnewell sorry it took a while.
https://github.com/beckend/xhr-mock/blob/xhr_debug/test/debug.test.ts
You can clone the branch and test, the fetchXHR
is used in production and is working intended in a webrowser.
The tests should pass but do not, it's the problem i have described in this thread.
Sorry I've taken so long to respond! I had some time on the train to investigate this today - thanks for your detailed repo!
xhr-mock
wasn't emitting upload progress events because you were using an empty string for the body and it was evaluating to false. I've fixed the issue and released xhr-mock@2.0.0-preview.10
. https://github.com/jameslnewell/xhr-mock/blob/master/src/MockXMLHttpRequest.ts#L221
re the loadend
event, I think it depends on what type of error occurred. Is that your understanding too? https://xhr.spec.whatwg.org/#request-error-steps
Currently only one type of error handling is implemented and we don't have a way to tell xhr-mock
which type of error handling to execute. What do you think of something like:
import mock, {RequestError, ResponseError, EndOfBodyError} from 'xhr-mock';
mock.get('/', () => Promise.reject(new ResponseError()));
looks fine to me, xhr was never easy to mock to begin with
does not seem to work yet