jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
883 stars 116 forks source link

Add tsconfig.json include/files property warning to README #111

Closed 13rac1 closed 5 years ago

13rac1 commented 5 years ago

If the "files" or "include" properties are set in the tsconfig.json file, then the setupJest.ts file must be included. Otherwise, the TypeScript compiler will fail to find fetchMock.

Example in tsconfig.json:

  "include": [
    "src/**/*",
    "test/**/*"
  ],

For fun: It'll work sometimes. I have a 100% reliable example where the existence of a newline at the top of the test file causes it to pass. Removing the newline causes it to fail.

Example failure:

$ jest
 FAIL  test/hello.test.ts
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    test/hello.test.ts:48:5 - error TS2304: Cannot find name 'fetchMock'.

    48     fetchMock.mockResponseOnce('Hello');
           ~~~~~~~~~
    test/hello.test.ts:67:12 - error TS2304: Cannot find name 'fetchMock'.

    67     expect(fetchMock).toBeCalledTimes(1);
                  ~~~~~~~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.451s
Ran all test suites.
13rac1 commented 5 years ago

No response in almost four months. Closing.