Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript] setupTests.ts not being respected #5666

Closed
christianchown opened this issue Nov 1, 2018 · 2 comments
Closed

[Typescript] setupTests.ts not being respected #5666

christianchown opened this issue Nov 1, 2018 · 2 comments

Comments

@christianchown
Copy link

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

@mrmckeb
Copy link
Contributor

mrmckeb commented Nov 2, 2018

This works for us, but we've import a shared config (which is JS). And we don't export anything from that file.

So, our setupTests.ts looks like:

import 'path-to-our-config/jest'; // a JavaScript file

@fbarbare
Copy link

We're facing the same issue, and it seems to happen on Windows only... works on my machine 😂

@ianschmitz ianschmitz changed the title [Typescript] setupTests.ts not being respecting [Typescript] setupTests.ts not being respected Nov 23, 2018
@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants