jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

Support XMLHttpRequest.DONE etc. #34

Closed michael42 closed 6 years ago

michael42 commented 6 years ago

As per spec, the XMLHttpRequest constructor should define the constants UNSENT = 0, OPENED = 1, HEADERS_RECEIVED = 2, LOADING = 3 and DONE = 4. Otherwise, the following snippet doesn't work as intended when using xhr-mock:

xhr.onreadystatechange = function () {
  if (xhr.readyState === XMLHttpRequest.DONE) {
    // ...
  }
}
jameslnewell commented 6 years ago

Hi @michael42. Can you please try xhr-mock@next for me (let me know if you have any issues!). It aligns much closer to the spec.

https://github.com/jameslnewell/xhr-mock/blob/master/src/MockXMLHttpRequest.ts#L37