question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inherit preview.js parameters handlers in stories

See original GitHub issue

As per Storybook rules of parameter inheritance, using msw in stories should inherit/concat the handlers from the preview.js parameters.

Example: The API I am using requires that I make a call for an oauth token before I can call any API call. In the current way this addon works, I have to duplicate this resolver in every single story that defines msw in its parameters because it overwrites the one from preview.js instead of merging with it.

preview.js

export const parameters = {
    actions: {argTypesRegex: '^on[A-Z].*'},
    msw: [
        rest.post('/oauth/token', (req, res, ctx) =>
            res(ctx.json({token_type: 'Bearer', access_token: 'test_token'}))
        ),
    ],
};

thing.stories.js

export default {
    component: Thing,
    parameters: {
        msw: [
            rest.get('/some/endpoint', (req, res, ctx) => 
                res(ctx.json([]))
            ),
        ],
    },
};

Both handlers should work in the story. Currently, the oauth/token handler is not included in the story.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
shilmancommented, Aug 4, 2021

@sklawren this is an interesting pattern. i wasn’t a fan initially because “object merge with array flattening” is harder to explain than “object merge”, but if one really wants to use arrays, this gets that AND merge AND backwards compatibility, which is pretty cool. A+ for creativity. my vote would still be for the simplicity of object merge, but i’ve got no horse in this race! 🏇

1reaction
shilmancommented, Aug 3, 2021

@kettanaito If you accumulate arrays then there’s no natural way to override anything that’s defined in a higher level in the hierarchy. The decision was made five years ago, so it’s all a distant memory at this point. But my recollection is that initially we merged arrays and then we backed it out based on problems it caused.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parameters - Storybook
Parameters are a set of static, named metadata about a story, typically used to control the behavior of Storybook features and addons.
Read more >
Configuring Storybook: 6 Tips You Can't Miss | by Zheng Li
To control the way stories are rendered and add global decorators and parameters, create a .storybook/preview.js file. This is loaded in the ...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Release 156 · Web Inspector · CSS · JavaScript · Rendering · Media · Web Animations · Accessibility · Web API.
Read more >
Layouts and Rendering in Rails - Ruby on Rails Guides
Rails will automatically render app/views/books/index.html.erb when you ... is done by nested classes of the module ActionView::Template::Handlers .
Read more >
Visualizing Data and Building Reports in Oracle Analytics Cloud
This topic covers how you capture insights and group them into stories. ... You can use preview mode to view and interact with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found