offbeat-dev / storybook-msw-addon

An MSW (Mock Service Worker) addon including a control panel that enables interaction and manipulation of mock requests within Storybook.
https://storybook-msw-addon.vercel.app
MIT License
25 stars 5 forks source link

Support handler merging #13

Closed tanner-equi closed 5 months ago

tanner-equi commented 5 months ago

The default behavior when working with Parameters is to have them override unless the value is an object. It would be nice to be able to leverage this to our advantage to do things like override global auth handlers to return errors while not overriding other global handlers.

// preview.tsx

export const parameters = {
  msw: {
    auth: someHandler,
    foo: globalHandler
  }
}
// foo.stories.tsx

export default {
  parameters: {
    auth: someOtherHandler,
    bar: myBarHandler
  }
}

This should be interpreted as:

[globalHandler, someOtherHandler, myBarHandler]
tanner-equi commented 5 months ago

Just kidding! Reading the code, it looks like this works out of the box! Thanks!