Skip to content

[Typescript] setupTests.ts not being respected #5666

Closed
@christianchown

Description

@christianchown

Is this a bug report?

Yes

Did you try recovering your dependencies?

No

Which terms did you search for in User Guide?

typescript, jest, setupTests

Environment

Environment:
OS: Windows 10
Node: 9.11.2
Yarn: 1.12.1
npm: 6.4.1
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found

Packages: (wanted => installed)
react: ^16.6.0 => 16.6.0
react-dom: ^16.6.0 => 16.6.0
react-scripts: 2.1.1 => 2.1.1

Steps to Reproduce

  1. npx create-react-app cra
  2. cd cra
  3. yarn add typescript @types/node @types/react @types/react-dom @types/jest enzyme enzyme-adapter-react-16 enzyme-to-json
  4. Rename App.js, App.test.js, index.js, serviceWorker.js -> App.tsx, App.test.tsx, index.tsx, serviceWorker.ts
  5. create setupTests.ts with:
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

export default undefined;
  1. Add the following lines to App.test.tsx
import { shallow } from 'enzyme';

it('matches snapshot', () => {
  expect(shallow(<App />)).toMatchSnapshot();
});
  1. Add the following to package.json
  "jest": {
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ]
  }
  1. yarn test

Expected Behavior

For Jest to create write __snapshots__/App.test.tsx.snap with a snapshot of <App />

Actual Behavior

● Validation Error:

Module /src/setupTests.js in the setupTestFrameworkScriptFile option was not found.
is: (...dir...)

Configuration Documentation:
https://jestjs.io/docs/configuration.html

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Notes

Renaming setupTests.ts -> setupTests.js does work

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions