-
-
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
How does jest-resolver treat ! in imports and requires? #4868
Comments
This comment has been minimized.
This comment has been minimized.
That's not valid identifiers, so jest doesn't understand them. You should use |
This comment has been minimized.
This comment has been minimized.
We appreciate Some samples. do you have one ? |
Did you read the docs linked above? |
@SimenB using inline loader overrides is a valid use-case of webpack.. I think it would be amiss for jest not to support at least some way of working with them? I tried adding the module to the |
What's your use case for a loader in this case? Could it be implemented as a transform? I still recommend sticking the loader in your webpack config to avoid tool-specific syntax in your code. An alternative is to implement the loader using a babel plugin. |
I was hoping that My use-case is as follows: I am using sass and have configured the sass/css loaders in my webpack.config. I have one occasion where I would like to import my main sass variables file into js using
|
@Billy- I see, I'd think that was supposed to work... Can you try putting a breakpoint here and see what happens when your code runs? https://github.com/facebook/jest/blob/819cae5f18b6dc99c16ee2fc4e2df4a93b782290/packages/jest-resolve/src/index.js#L362-L398
I still think it might be better to add that to |
Hmm, looks like it is hitting the mock now.. Must have been a typo or something cached. Sorry to waste your time, and thanks for the help! |
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
@Billy- could you provide the working example? Is not clear how you've managed to make it work. |
I solved this by adding the following to my jest config:
hope this helps others! |
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'm using script-loader for jquery plugins, and do a couple imports like this(in different places):
This is working at runtime on a browser, but not under Jest. I've tried adding script-loader.js to the __mocks__ folder next to node_modules and confirm that my mock code gets run when I just do
in a test file.
I'm wondering if the ! in the imports are messing up the resolution? The exact error I'm getting is:
Thanks!
Koby
The text was updated successfully, but these errors were encountered: