-
Notifications
You must be signed in to change notification settings - Fork 492
Usage with Enzyme, error: Enzyme expects an adapter #185
Comments
Experiencing the same issue. I've tried changing between "setupFiles" and "setupTestFrameworkScriptFile", using 'require()', 'import * as'. Same error. |
@quantuminformation Fixed my issue by using the answer found here: |
Similar to @adepatie and the stackoverflow above, I have a working setup with the following: package.json ...
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "^1.0.2",
"@types/enzyme": "^3.1.0",
"react-scripts-ts": "2.8.0",
... setupTests.ts: import * as enzyme from 'enzyme';
import * as Adapter from 'enzyme-adapter-react-16';
enzyme.configure({ adapter: new Adapter() }); |
Thanks for the workaround people ❤️ I've been having similar problems. It looks like src/setupTests.js is not running before every test file (as it should). I work around the issue by adding: import * as Adapter from 'enzyme-adapter-react-15';
configure({ adapter: new Adapter() }); to the test suite, which works fine for now since it's a small project with not many suites. |
Hey @NirBenita have you tried renaming that file to setupTests.ts ? |
Could someone submit a PR to get this working correctly? |
|
It does not work at all for me
|
@abenchi , would you mind elaborating this ? "It does not work" lacks precision. |
Instructions on how to setup |
Indeed, it was my error, by doing the follwing to avoid the requestAnimationFrame warnings
I override the setupTests... |
This error occurs when you are using React16, and trying to install Enzyme@2 with "npm i --save-dev enzyme",
import Enzyme from 'enzyme'; Enzyme.configure({ Now you need to add jest.config.json file on the root as it, this will tell to run raf then setupTests.js file Update this in package.json file: |
A simple solution is here: |
It is my sample used
|
@quocdai92 you save my day.... works for me
and inside src folder I put setupTests.js |
Created project using create-react-app, added Enyzme but go this error setUpTest.js import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() }); found out that i had a typo changed file to setupTests.js and ran package.json {
"name": "react_version",
"version": "0.1.0",
"private": true,
"dependencies": {
"@reach/router": "^1.2.1",
"react": "^16.7.0-alpha.2",
"react-dom": "^16.7.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.2",
"styled-components": "^4.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
}
} |
I have the following setup
but get this error:
I get the same error if I rename to
setupTests.ts
The text was updated successfully, but these errors were encountered: