Closed jardimfelipe closed 1 month ago
As far as I understand, the problem is that Jest is not able to use dynamic imports (this is a feature of webpack) The solution is to mock require.context or u can polyfill it, see here
As @EgorFront mentioned, there are a number of solutions. My preferred solution has usually been to isolate the require.context
call in a file that can be mocked, but I'm thinking about possibly building in an automatic workaround to the problem - the issue is none of the ones I know of are really ideal, so I'll probably have build in something custom.
Adding a babel-plugin-transform-require-context
plugin to .babelrc
helps me solve the issue.
https://www.npmjs.com/package/babel-plugin-transform-require-context
Just add into .babelrc
for test
env and it will fix the issue
{ "env": { "test": { "plugins": ["transform-require-context"] } } }
@satyamqainfotech
Adding a
babel-plugin-transform-require-context
plugin to.babelrc
helps me solve the issue.https://www.npmjs.com/package/babel-plugin-transform-require-context
Just add into
.babelrc
fortest
env and it will fix the issue
{ "env": { "test": { "plugins": ["transform-require-context"] } } }
Is this all you did? Because I can't get this to work.
Also, I'm new to Jest and not sure how to mock this if that is what I have to do.
tHanks.
@satyamqainfotech
Adding a
babel-plugin-transform-require-context
plugin to.babelrc
helps me solve the issue. https://www.npmjs.com/package/babel-plugin-transform-require-context Just add into.babelrc
fortest
env and it will fix the issue{ "env": { "test": { "plugins": ["transform-require-context"] } } }
Is this all you did? Because I can't get this to work.
Also, I'm new to Jest and not sure how to mock this if that is what I have to do.
tHanks.
Hey @beamsies - See this answer: https://stackoverflow.com/a/61137440/7358308, also you can look at other answers and try it out
I used this package to fix this problem: https://www.npmjs.com/package/require-context.macro
Sorry for the delay in responding to this. I let the project lapse and am in the process of currently updating it to Vue 3 standards.
In order to clean up issues, I'll be closing this issue at this time, but if you still have issues with the new boilerplate or have questions, please don't hesitate to open another issue.
I used
yarn new module
command to create a new vuex module to test my app. However, I stumbled in the following error:This error occurs on every vuex module file.
Bellow, this is an example of a vuex module:
And this is its test:
This error doesn't occurs on newly created module using
yarn new modules
so I'm probably doing something wrong. If anybody have any clues in this matter, I would be very grateful