Currently, the presence of a timeout on a request, forces MockXMLHttpRequest.send() to take the timeout path, even when the response returned by the handler indicates no timeout. Additionally, if the response indicates a short timeout, a long timeout on the request is preferred.
Basically, this means it's not possible to test the non-timeout path of code that sends a request with a timeout. i.e., code like this:
const req = new XmlHttpRequest();
// Indicate the ability to handle a timeout.
req.timeout = 1000;
req.ontimeout = () => ...;
// ...but express the expected happy-path as a regular onload event
req.onload = () => ...;
I believe that MockXMLHttpRequest::timeout should only indicate the capacity to handle a timeout, but MockXMLHttpResponse::timeout should indicate the choice to take the timeout path.
This PR updates MockXMLHttpRequest::send() so that it only takes the timeout path when a response timeout is indicated.
Currently, the presence of a timeout on a request, forces
MockXMLHttpRequest.send()
to take the timeout path, even when the response returned by the handler indicates no timeout. Additionally, if the response indicates a short timeout, a long timeout on the request is preferred.Basically, this means it's not possible to test the non-timeout path of code that sends a request with a timeout. i.e., code like this:
cannot have its onload path tested (even with
res.timeout(false)
orres.timeout(0)
), because the presence ofreq.timeout
forces the timeout path, due to theMath.max()
here: https://github.com/marvinhagemeister/xhr-mocklet/blob/master/src/MockXMLHttpRequest.ts#L217I believe that
MockXMLHttpRequest::timeout
should only indicate the capacity to handle a timeout, butMockXMLHttpResponse::timeout
should indicate the choice to take the timeout path.This PR updates
MockXMLHttpRequest::send()
so that it only takes the timeout path when a response timeout is indicated.