JohnAlbin / storybook-addon-fetch-mock

Adds fetch-mock to Storybook
Other
8 stars 5 forks source link

Body matcher not working, even with partialBodyMatcher on PUT request #23

Open tomraine-etrainu opened 3 months ago

tomraine-etrainu commented 3 months ago

I am trying to set a body matcher that checks for a "fail" string in a body property.

const mocks = [
  /* This doesn't seem to work but according to the docs is should */
  {
    matcher: {
      name: 'usePutUpdateError',
      url: `glob:*/skills/admin/activity/entries/*/qualification`,
      method: 'PUT',
      body: {
        changeReason: 'fail',
      },
      matchPartialBody: true,
    },
    response: {
      status: 400,
      body: {},
    },
    options: {
      delay: 250,
    },
  },
  {
    matcher: {
      name: 'usePutUpdateSuccess',
      url: `glob:*/skills/admin/activity/entries/*/qualification`,
      method: 'PUT',
    },
    response: {
      status: 200,
      body: {},
    },
    options: {
      delay: 750,
    },
  },
];

The second matcher here works as expected. Any ideas on this one, it doesn't work if I match the entire body object either.