Closed Dani-Boy92 closed 3 years ago
Hey, @Dani-Boy92.
If you're using our storybook add-on, please don't skip it's initialization step:
// ./storybook/preview.js
import { addDecorator } from '@storybook/react';
import { initializeWorker, mswDecorator } from 'msw-storybook-addon';
initializeWorker();
addDecorator(mswDecorator);
This way you don't need to call worker.start()
manually next to your story, which subjects it to a race condition, resulting in all sorts of unpredictable behavior.
export const decorators = [
(Story) => (
<Provider store={store}>
<Story />
</Provider>
),
];
-// get the mocked handlers (endpoints) and starts the service worker
-if (typeof global.process === "undefined") {
- const { worker } = require("../src/browser");
- worker.start();
-}
Could you please follow this suggestion and let me know if the issue is fixed?
Please use our Storybook add-on I've mentioned above. If it still doesn't work after you've followed the getting started instructions from its documentation, please open an issue in its repository. Thanks.
Hello,
I am new to MSW and have the problem that msw returns the correct mock APIs after the first load, but after a reload / hotreload, e.g. due to a change in the code, it does not work anymore and the connection fails.
I am working with Storybook and RTK Query (but also tried it with different REST libraries).
storybook/preview.js
.../src/browser.js
.../src/handlers.js
component with mocked API request
Environment
msw: "^0.35.0
,msw-storybook-addon": "^1.3.0
,nodejs: v12.16.1
,yarn: v1.22.4