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

Mocking 2 responses with the same url, but with different status #229

Open
sekmo opened this issue Mar 1, 2022 · 1 comment
Open

Mocking 2 responses with the same url, but with different status #229

sekmo opened this issue Mar 1, 2022 · 1 comment

Comments

@sekmo
Copy link

sekmo commented Mar 1, 2022

Hello everyone! Is it possible to mock 2 responses with the same method and URL, but making the first one returning a 400 and the second one a 200?

@sekmo
Copy link
Author

sekmo commented Mar 1, 2022

Sorry, I just saw right now that I can use a function to process the response, so I guess that something like this would be the answer:

let amountOfCalledFetchMocks = 0
fetchMock.get('begin:http://test.test/', () => {
  amountOfCalledFetchMocks++;
  if(amountOfCalledFetchMocks == 1) {
    return 400;
  } else {
    return 200;
  }
});

Please let me know if you have a better solution, thanks :)

@sekmo sekmo changed the title Mocking 2 responses with the same url, but first fails and the second succeeds Mocking 2 responses with the same url, but with different status Mar 1, 2022
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

1 participant