Closed adrianpiw closed 5 months ago
Hey there @maleficv, the issue you're facing is not related to the addon, but to the fact that you're setting up MSW yourself in the server.ts file:
server.ts
import { setupServer } from 'msw/node'
import { handlers } from './handlers'
export const server = setupServer(...handlers)
and you're telling that server to start listening during your tests.
beforeAll(() => {
server.listen();
});
that is overwriting the behavior of the MSW instance from the addon.
If you don't use that at all, things should just work. You can get access to the MSW instance used by the addon via the getWorker function: import { getWorker } from 'msw-storybook-addon'
Hey there @maleficv, the issue you're facing is not related to the addon, but to the fact that you're setting up MSW yourself in the server.ts file:
server.ts import { setupServer } from 'msw/node' import { handlers } from './handlers' export const server = setupServer(...handlers)
and you're telling that server to start listening during your tests.
beforeAll(() => { server.listen(); });
that is overwriting the behavior of the MSW instance from the addon.
If you don't use that at all, things should just work. You can get access to the MSW instance used by the addon via the getWorker function:
import { getWorker } from 'msw-storybook-addon'
I see, so the addon was spinning it's own instance of worker and I duplicated that, replacing the addon one manually.
That fixes an issue, thank you a lot
The problem:
I have globally defined handlers in preview file and they work as expected, then I have a story file, that has it's own interceptors, it's basically the same api endpoint as in globals but for particular story I want to have different response. This is working perfectly fine in storybook itself, but when I import the story to test file, it ignores the story specific msw handlers, and global ones are used instead.
When I'm importing a Story component in different file, I'm expecting to have this particular stories applied too.
Downgrading package to 2.0.0 resolves this issue and it's having unexpected behaviour on version 2.0.1 and 2.0.2
In below example, during the test being executed, I'd expect a value of api response to be "story" which means, it's interceptor comes form the story itself, instead it's equal to "handlers" which means, the story interceptor is not used, it's the global one from handlers.
Stack:
Packages:
Storybook previews file
Story file
Button test file
vitest file
setup file
server setup file