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
Using the addon v2 with Jest #145
Comments
I'm in the exact same boat! Unfortunately, nothing has worked for me either. What I'm getting: demo-repo-folder/node_modules/msw-storybook-addon/dist/index.browser.js:2
import { setupWorker } from "msw/browser";
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import { initialize, mswLoader } from 'msw-storybook-addon'
| ^
2 |
3 | initialize({ onUnhandledRequest: 'bypass' })
4 |
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
at Object.require (.storybook/baseLoaders.tsx:1:1)
at Object.require (.storybook/testConfig.ts:2:1)
at Object.require (src/components/DemoComponent/__tests__/DemoComponent.test.tsx:6:1) |
Same issue here. Then, Getting stuck with the same error
|
Doing like this will run both storybook and jest. But still throw another error regarding msw mock
|
I have the same issue with the following error.
looks like the issue is with use of "jsdom" testing environment together with |
after doing everything that @dmitriy-kudelko mentioned in the description and https://jestjs.io/docs/configuration#testenvironmentoptions-object
basically this does the same that @kodai3 did in his last answer but via jest |
Thanks, it indeed replaces my code for me as well The error I get after adding those workaround.
it seems to be caused by
|
@kodai3 I have |
I confirm. This worked for me as well. Thanks for the update! 👍 |
but I have another issues now. looks like response is not returned from my mocked request. |
The queries (gql queries and mutations for may usecase) I mocked via storybook's and that was the cause the error I mentioned above through our validation. |
Yeah.. same here. |
Re-adding mswDecorator fixed for me.
|
also had error inside added:
also it worked for me without adding |
🚀 Issue was released in |
Hey @dmitriy-kudelko @alextrukhan @kodai3 @SamSverko could you please try 2.0.1 out and let me know if all goes well? |
It seems |
@yannbf
I still get the following error: |
@yannbf , same here. I also don't see any improvement in the behavior in this regard. |
Hello,
I spent some time migrating from v1 (both msw and the addon) to v2. And it almost worked except for tests (Jest).
A first problem was that the module needed to be tranformed, otherwise throwing:
So I had to add
msw-storybook-addon
to jest configtransformIgnorePatterns
so that it's transformed.Then I got:
So I found that in this case we need to add some polyfills, which I did: https://mswjs.io/docs/migrations/1.x-to-2.x/#requestresponsetextencoder-is-not-defined-jest
However after doing this Jest throws another error:
Is there a recommended way to make it work with Jest?
The text was updated successfully, but these errors were encountered: