Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to customize default handlers in Story #105

Closed
jpzwarte opened this issue Mar 18, 2023 · 2 comments
Closed

Unable to customize default handlers in Story #105

jpzwarte opened this issue Mar 18, 2023 · 2 comments

Comments

@jpzwarte
Copy link

export default {
  title: 'Example',
  parameters: {
    msw: {
      handlers: [
        rest.get('/foo', ....),
        rest.get('/bar', ....),
      ]
    }
} satisfies Meta<Props>;

type Story = StoryObj<Props>;

export const Story: Story = {
  parameters: {
    msw: {
      handlers: [
        // Overwrite or add a handler here; you lose the /bar handler here
        rest.get('/foo', ....)
      ]
    }
  }
};

So in the "Story" story, you lose the /bar handler. My expectation was that I could add or overwrite any default handlers in a story.

@jpzwarte
Copy link
Author

RTFM: https://github.com/mswjs/msw-storybook-addon#composing-request-handlers

@awreese
Copy link

awreese commented Jul 31, 2024

I guess the piece that was unclear and tripped me up for a while is the fact that all parameters.msw.handlers need to be objects with keys in order for inheritance to work as expected, in the default exports and in individual stories. The Composing request handlers doesn't explicitly state this is the case. Of course in hind site this totally makes sense now.

@yannbf I created #158 to address this in the README and hopefully make this clearer for the next dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants