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

How test with Jest? #54

Closed
darkowic opened this issue May 10, 2017 · 8 comments
Closed

How test with Jest? #54

darkowic opened this issue May 10, 2017 · 8 comments

Comments

@darkowic
Copy link

darkowic commented May 10, 2017

I'm trying to setup Jest tests configuration for my project. I use imports-loader to load some old jQuery libs

import 'imports-loader!jquery-mousewheel'

When running tests with jest I get following error:

 Cannot find module 'imports-loader!jquery-mousewheel' from 'SomeModule.js'

As a workaround, I mock all imports-loader in Jest config

"moduleNameMapper": {
  "imports-loader?.*": "<rootDir>/internals/mocks/importsLoader.js"
},
// importsLoader.js
module.exports = 'IMPORTS_LOADER_MOCK';

How to configure it to actually import correct module?

@thedv91
Copy link

thedv91 commented Nov 14, 2017

I have same issue. You solved it?

@darkowic
Copy link
Author

Unfortunately no @chacbumbum

@maxcodes
Copy link

maxcodes commented Dec 7, 2017

Bump. Stuck with the same issue

@nickangtc
Copy link

nickangtc commented Dec 21, 2017

Thanks @darkowic I needed just a solution to mock all the require('imports!...') blocks, your moduleNameMapper solution worked for me 👍

@am
Copy link

am commented May 2, 2018

Facing the same issue but with expose-loader.

@technoligest
Copy link

Anyone had any luck with this? @darkowic I do not completely understand your approach, can you please elaborate?

@darkowic
Copy link
Author

darkowic commented Apr 6, 2019

The workaround simply imports string instead of the real module

duleorlovic added a commit to trkin/trk_datatables_js that referenced this issue Oct 3, 2019
This notation
```
require('imports-loader?define=>false,this=>window!datatables.net')(window, $)
```
break jest test
webpack-contrib/imports-loader#54
and they suggest to use loaders in webpack config
jestjs/jest#4868
but that will complicate installation in rails since we need to
configure webpacker to disable amd only for datatables.net dependency
@alexander-akait
Copy link
Member

Here a lot of examples - https://jestjs.io/docs/en/webpack, if somebody still have problems, please open an issue in jest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants