-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
"expect is not defined" when importing jest-enzyme in setup.js #86
Comments
Could you try upgrading to 3.1.0? |
I had 3.1.1, downgrading to 3.1.0 didn't fix the problem. |
@andriichernenko did you figure this out? I honestly have no clue why your environment would be doing that. |
@blainekasten no, I did not. I ended up not using |
Ah, sorry about this. Wish I could help more! Thanks for trying it out |
Hey @andriichernenko, I stumbled across this myself trying to use the
Let me know if that helps. |
For anyone stumbling across this in 2019, @michaelgmcd's answer works but Jest's |
@mulholio interested in submitting a PR to update docs? |
If you're still having the issue after the above, try updating your node version. We were attempting against node 10, and it did not pass, but upgrading to 13 fixed. |
I followed this guide and finally it worked: |
I am facing the same issue: module.exports = {
preset: 'react-native',
collectCoverage: true,
moduleDirectories: ['node_modules', 'src'],
transform: {
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
setupFiles: ['<rootDir>setup-tests.js'],
transformIgnorePatterns: ['node_modules/(?!(jest-)?react-native)'],
coveragePathIgnorePatterns: ['/node_modules/', '/jest'],
testEnvironment: 'jsdom',
}; setup-tests.js import 'react-native';
import 'jest-enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Enzyme from 'enzyme';
/**
* Set up DOM in node.js environment for Enzyme to mount to
*/
const {JSDOM} = require('jsdom');
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const {window} = jsdom;
function copyProps(src, target) {
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target),
});
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
copyProps(window, global);
/**
* Set up Enzyme to mount to DOM, simulate events,
* and inspect the DOM in tests.
*/
Enzyme.configure({adapter: new Adapter()}); Env.
|
Same issue, fixed by upgrading node v10.10 --> v10.15 (see original comment) |
I am using Jest 20 with Enzyme 2.8.0.
Importing
jest-enzyme
in my test files works, but as soon as I put it in mysetup.js
I am getting the following error:Here's my
setup.js
file:I tried rolling back to Jest 19 and putting the import at the end of file, didn't help.
What could be the problem?
The text was updated successfully, but these errors were encountered: