Skip to content

Commit

Permalink
HttpProviderTest extended
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed May 6, 2019
1 parent 8d8b129 commit 22c8c49
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/web3-providers/tests/src/providers/HttpProviderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,35 @@ describe('HttpProviderTest', () => {
expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
});

it('calls sendPayload and returns with a rejected promise because the request status is between 400 and 499', async () => {
new XHR();
const xhrMock = XHR.mock.instances[0];

xhrMock.readyState = 4;
xhrMock.status = 450;
xhrMock.responseText = 'NOPE';

providersModuleFactoryMock.createXMLHttpRequest.mockReturnValueOnce(xhrMock);

setTimeout(() => {
xhrMock.onreadystatechange();
}, 1);

await expect(httpProvider.sendPayload({id: '0x0'})).rejects.toThrow(
`HttpProvider ERROR: NOPE (code: 450)`
);

expect(providersModuleFactoryMock.createXMLHttpRequest).toHaveBeenCalledWith(
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent,
httpProvider.withCredentials
);

expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
});

it('calls sendPayload and returns with a rejected promise because the request.send() method throws an error', async () => {
new XHR();
const xhrMock = XHR.mock.instances[0];
Expand Down

0 comments on commit 22c8c49

Please sign in to comment.