UNPKG

943 BJavaScriptView Raw
1// avoid circular dependency when using jest.mock()
2let fetch;
3try {
4 // note that jest is not a global, but is injected somehow into
5 // the environment. So we can't be safe and check for global.jest
6 // Hence the try/catch
7 fetch = jest.requireActual('node-fetch'); //eslint-disable-line no-undef
8} catch (e) {
9 fetch = require('node-fetch');
10}
11const Request = fetch.Request;
12const Response = fetch.Response;
13const Headers = fetch.Headers;
14const Stream = require('stream');
15const FetchMock = require('./lib/index');
16const http = require('http');
17const { setUrlImplementation } = require('./lib/request-utils');
18setUrlImplementation(require('whatwg-url').URL);
19
20FetchMock.global = global;
21FetchMock.statusTextMap = http.STATUS_CODES;
22FetchMock.Stream = Stream;
23
24FetchMock.config = Object.assign(FetchMock.config, {
25 Promise: Promise,
26 Request: Request,
27 Response: Response,
28 Headers: Headers
29});
30
31module.exports = FetchMock.createInstance();