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

matchMock() now also matches GET = get (case insensitive) #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pkyeck
Copy link

@pkyeck pkyeck commented May 14, 2024

I had the problem that one of my mocks was ignored and the actual request was sent out even though others were working.

Had my mock defined like this:

{
  url: '/',
  method: 'POST',
  ignoreQueryParams: true,
  status: 200,
  response: {
    message: 'ok',
  },
}

And was grabbing the method from a <form> element and passing to fetch() like so:

const formEl = module as HTMLFormElement;
const { action, method } = formEl;

// ...

const response = await fetch(action, {
  method,
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({}),
})

But the mock didn't work ... only after debugging for a while, I realized that the method I got from the HTMLFormElement was lowercase and the reason why the faker wasn't matching my mock with the fetch-request.

This change allows both versions: GET and get or POST and post.

Copy link

netlify bot commented May 14, 2024

Deploy Preview for storybook-addon-mock ready!

Name Link
🔨 Latest commit 1012e78
🔍 Latest deploy log https://app.netlify.com/sites/storybook-addon-mock/deploys/66570a1890b54b00084c9289
😎 Deploy Preview https://deploy-preview-212--storybook-addon-mock.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

to make Mock Request panel scrollable
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

Successfully merging this pull request may close these issues.

None yet

1 participant