Allow `parameters.msw` to be a function that takes `args`
See original GitHub issueHello! I’m stoked to see this library growing so much. At work we still have a custom setup for Storybook and MSW because we’re using args
to result in dynamic MSW calls.
I wonder if you could add something like
if (typeof context.parameters.msw === "function") {
api.use(...context.parameters.msw(context.args))
}
Where the story meta would be:
export default {
...,
args: { isLoading },
parameters: {
msw: (args) => [
rest.get("...", (_, res, ctx) =>
res(ctx.delay(args.isLoading ? "infinite" : 0), ctx.json(...))
)
]
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
Query parameters - Recipes - Mock Service Worker Docs
Query parameters. In order to access a query parameter of the intercepted request, use the searchParams property on the req.url instance.
Read more >passing arguments to functions in python using argv
Command line arguments are passed as an array to the program, with the first being usually the program's location. So we skip argv[0]...
Read more >Parameters - Storybook
The way the global, component and story parameters are combined is: More specific parameters take precedence (so a story parameter overwrites a component ......
Read more >Args and addons - Storybook for React Apps
Make a clone of Template function for code reuse by using .bind({}) ... It also allows you to reuse the args from one...
Read more >Use parameters to ask for input when running a query
You can set the parameter to accept only a certain type of data. It is especially important to specify the data type for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @itaditya thanks for referring that! There are a couple of things happening on the storybook side that will allow us to bring a proper control panel experience to this addon, I just need to discuss more with the team and prototype in this addon:
Targeted args will allow users to define args specifically for addons, which will not be passed down to the components props
Loaders that rerun on args change will allow us to move from exporting decorators to loaders so that the mock setup is done before the component renders (then we can support nextjs and its getServerProps for instance) and the mocks will be redone on args change
So @tmikeschu this feature is definitely going to happen, it might just take some time!
Very excited for this feature. Let me know if you want assistance writing these changes.
I was able to make it work by implementing my own handler which could be done at the story or component level.
Example here: