Answer a question

I have read that src/setupTests.js is supposed to load before every test but I still get every test failing with the error:

"Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none."

this is my src/setupTests.js

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'whatwg-fetch';

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

Here is my package.json:

"devDependencies": {
"babel-core": "^6.26.3",
"babel-jest": "^23.6.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"coveralls": "^3.0.2",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"enzyme-to-json": "^3.3.4",
"jest": "^23.6.0",
"react-test-renderer": "^16.5.2",
"redux-mock-store": "^1.5.3",
"regenerator-runtime": "^0.12.1",
"whatwg-fetch": "^3.0.0"
}

I am running a "test" script via npm run test

"scripts": {
  "test": "jest",
  "test:watch": "jest --watch",
  "test:updateSnapshots": "jest --updateSnapshot"
}

I start every test file with some form of the following:

import React from 'react';
import { shallow } from 'enzyme';

I am on React 16 with react-scripts 2.1.1

Am I doing anything wrong that anyone can see?

Answers

Does it work when you add the following to your package.json

"scripts": {
  ...
  "test": "react-scripts test",
  ...

}
Logo

React社区为您提供最前沿的新闻资讯和知识内容

更多推荐