mirror of
https://github.com/status-im/react-native.git
synced 2025-01-29 10:45:04 +00:00
d363b1f2e2
Reviewed By: javache Differential Revision: D3229435 fb-gh-sync-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c fbshipit-source-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
jest
|
|
.disableAutomock()
|
|
.unmock('XMLHttpRequestBase');
|
|
|
|
const XMLHttpRequestBase = require('XMLHttpRequestBase');
|
|
|
|
describe('XMLHttpRequestBase', function(){
|
|
var xhr;
|
|
|
|
beforeEach(() => {
|
|
xhr = new XMLHttpRequestBase();
|
|
xhr.ontimeout = jest.fn();
|
|
xhr.onerror = jest.fn();
|
|
xhr.onload = jest.fn();
|
|
xhr.didCreateRequest(1);
|
|
});
|
|
|
|
afterEach(() => {
|
|
xhr = null;
|
|
});
|
|
|
|
it('should call ontimeout function when the request times out', function(){
|
|
xhr._didCompleteResponse(1, 'Timeout', true);
|
|
|
|
expect(xhr.ontimeout).toBeCalledWith(null);
|
|
expect(xhr.onerror).not.toBeCalled();
|
|
expect(xhr.onload).not.toBeCalled();
|
|
});
|
|
|
|
it('should call onerror function when the request times out', function(){
|
|
xhr._didCompleteResponse(1, 'Generic error');
|
|
|
|
expect(xhr.onerror).toBeCalledWith(null);
|
|
expect(xhr.ontimeout).not.toBeCalled();
|
|
expect(xhr.onload).not.toBeCalled();
|
|
});
|
|
|
|
it('should call onload function when there is no error', function(){
|
|
xhr._didCompleteResponse(1, null);
|
|
|
|
expect(xhr.onload).toBeCalledWith(null);
|
|
expect(xhr.onerror).not.toBeCalled();
|
|
expect(xhr.ontimeout).not.toBeCalled();
|
|
});
|
|
|
|
});
|