jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

xhr.readyState = 2 // xhr.status = 0 #84

Open piotrzdziarski opened 5 years ago

piotrzdziarski commented 5 years ago

Normally in browser when headers are received status is received too, but in this package status is 0:

xhrMock.setup();
xhrMock.get('/endpoint', {
    status: 200
});

const xhr = new XMLHttpRequest();
xhr.open('GET', '/endpoint', true);
xhr.send();
xhr.onreadystatechange = () => {
    if (xhr.readyState === 2) {
        console.log(xhr.status); // outputs: 0
    }
};

I think it should already return passed status.

mariuslundgard commented 4 years ago

I'm having the same issue!