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

Add "continue" helper #1694

Closed
1 task
kentcdodds opened this issue Aug 10, 2023 · 2 comments
Closed
1 task

Add "continue" helper #1694

kentcdodds opened this issue Aug 10, 2023 · 2 comments
Labels

Comments

@kentcdodds
Copy link
Contributor

Scope

Adds a new behavior

Compatibility

  • This is a breaking change

Feature description

I would like to be able to do this:

	const email = faker.internet.email()
	let emailRequest: Request
	server.use(
		rest.post(`https://api.resend.com/emails`, async ({ request }) => {
			emailRequest = request
			return continue()
		}),
	)

This would allow me to override the handler just to get the request so I can make assertions on it, but then let msw continue to look for another existing handler that will handle this request.

@kettanaito
Copy link
Member

Hi, @kentcdodds. The fallthrough behavior is already implemented and it's the default behavior MSW exhibits.

Fallthrough in 1.x

In version 1.x, it's enough to return undefined from the resolver to tell MSW to keep looking for any other matching handler.

rest.get('/resource', (req, res, ctx) => {
  // ...any side-effects.
  return
})

Fallthrough in 2.x (#1404)

In version 2.x, it works the same way: MSW keeps iterating until it meets a handler that returns a response:

// Stop the lookup if this handler returns a mocked response.
// If it doesn't, it will still be considered the last matching
// handler until any of them returns a response. This way we can
// distinguish between fallthrough handlers without responses
// and the lack of a matching handler.
if (result?.response) {
break
}

Did you experience an issue with this behavior? I'm rather confident it's stable in 1.x but I might have introduced a regression in the 2.x rewrite. If that's the case, please let me know. Thanks.

@kentcdodds
Copy link
Contributor Author

Ah! That makes plenty of sense. I'll test it out and let you know if I have issues. I guess I forgot about this behavior 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants