Comments (7)
Got it working, instead of using mswLoader, I'm now using mswDecorator. Not sure why.
from msw-storybook-addon.
That's great! Thank you for reporting back. I will be closing this issue, let me know if this happens again.
from msw-storybook-addon.
Thank you!
from msw-storybook-addon.
I'm having issues too. made it work with this workaround: #119 (comment)
But I can't define handlers for each Story.
Did you have any luck?
from msw-storybook-addon.
Hey @conradogarciaberrotaran and @Mexflubber thanks for reporting this.
The mswLoader is the recommended way to use the addon because it avoids possible flakiness, as the decorator only runs as the story is rendering, while the loader runs before the story renders. But the mswLoader waits for the msw promise to resolve, and it seems like it never resolves for you. Could you please share a reproduction? That will make it much easier for me to understand what's going on and to provide a fix for it.
from msw-storybook-addon.
Thank you @yannbf , I've just tried to replicate the issue, basically I ran:
npx create-next-app@latest msw-storybook-issue --use-npm
npx storybook@latest init
npm i msw msw-storybook-addon -D
npx msw init public/
Added the public route of my nextjs to the staticDirs in main.js and added this story:
import { rest } from 'msw';
import { useEffect, useState } from 'react';
const SomeComponent = () => {
const [response, setResponse] = useState(null);
useEffect(() => {
fetch("/api/some-endpoint")
.then((response) => response.json())
.then((data) => setResponse(data));
}, []);
return <div>{response?.firstName}</div>;
};
export default {
title: 'Example/SomeComponent',
component: SomeComponent,
};
export const Something = {
parameters: {
msw: {
handlers: [
rest.get('/api/some-endpoint', (req, res, ctx) => {
return res(
ctx.json({
firstName: 'Neil',
lastName: 'Maverick',
})
)
}),
]
},
}
};
export const SomethingElse = {
parameters: {
msw: {
handlers: [
rest.get('/api/some-endpoint', (req, res, ctx) => {
return res(
ctx.json({
firstName: 'bob',
lastName: 'Maverick',
})
)
}),
]
},
}
};
And it's working correctly.
I'm not able to reproduce it. I will try updating the versions on my project to see if the issue is fixed.
from msw-storybook-addon.
Updating the libraries fixed my issue, I updated msw, storybook and msw-storybook-addon to latest
from msw-storybook-addon.
Related Issues (20)
- Problems with SB7: 404s on mocked calls and mockServiceWorker.js retrieval HOT 1
- Unable to customize default handlers in Story HOT 1
- Possible issue when used with build-storybook HOT 2
- [README.md] static dir should be indicated using `.storybook/main.js` instead of `-s` option HOT 3
- Storybook keeps reloading when this add-on is enabled HOT 2
- How to overwrite the handlers using the array definition? HOT 1
- Not catching API as expected HOT 2
- Always 404 error returns on next.js environment HOT 8
- Can´t intialize msw on Sveltekit + Typescript HOT 1
- Support for MSW 2.0.0 HOT 26
- MSW 2.0 Support HOT 1
- Do not know how I can mock my RTK websocket with this lib HOT 3
- Can not able to import msw-storybook-addon HOT 1
- Breaks on building Storybook HOT 18
- Quick question on this library HOT 2
- Running msw-storybook-addon within test-storybook HOT 1
- codesandbox for using the addon HOT 1
- Help when building storybook and deploying on Vercel HOT 10
- Peer dependencies breaking install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msw-storybook-addon.