How to add custom mock handlers for MSW in Storybook

You can add them in web/config/storybook.preview.js:

import React from 'react'

import { registerHandler } from '@redwoodjs/testing/web'

import { handlers } from '../src/mocks'

export const decorators = [
  (Story) => {
    React.useEffect(() => {
      for (const handler of handlers) {
        registerHandler(handler)
      }
    }, [])
    return <Story />
  },
]
1 Like