-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Jest doesn't work with global jquery #708
Comments
You can load jQuery in a setup file, see https://facebook.github.io/jest/docs/api.html#config-setupenvscriptfile-string window.$ = require('path/to/jquery'); for example. |
In package.json: "jest": {
"setupFiles": ["./source/setup-jest.js"]
}, In source/setup-jest.js import $ from 'jquery';
global.$ = global.jQuery = $; |
Thanks for that @charliecalvert -- Been trying to wire up unit tests to my clients Shopify store repo, this helped a lot! |
Worked for me as well, thank you! |
Doesn't work for me! |
setting up my
Does not work for me either. I'm trying to run a test for my bootstrap Modal and says that modal is not a function. |
This works for me: global.jQuery = require('jquery');
global.$ = global.jQuery; |
If it's not working for you, make sure you're not using ES |
What worked for me, was adding transformIgnorePatterns: [
"<rootDir>/node_modules/(?!bootstrap/)",
], |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I have setup jest with webpack according to articles from https://facebook.github.io/jest/docs/getting-started.html. All works fine except I have got third party libraries which requires reference to global jquery. I have configured webpack in the next way
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
so it works when I run my app, but when I try to run test it says jQuery is not defined. What can I do with this issue?
The text was updated successfully, but these errors were encountered: