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 an option to MockProvider to throw when a request fails to match a mock #420

Open
JonnyIngeno opened this issue Jan 24, 2024 · 0 comments
Labels
🧪 testing Feature requests related to testing

Comments

@JonnyIngeno
Copy link

JonnyIngeno commented Jan 24, 2024

MockProvider currently offers an option showWarnings with the following description:

When a request fails to match a mock, a warning is logged to the console to indicate the mismatch. Set this to false to silence these warnings.

The default value is true.

The problem is that it's insufficient for robust testing because showing a warning doesn't fail the tests.

For reliable integration tests, no network request should actually hit the network. A warning is easily missed in the tests output logs and unfortunately we're shipping that code because the tests passed while we didn't want them to. This often leaves a plethora of garbage in the tests output logs that we need to fix after the fact...

What we need is an option to fail the tests on such occasion:

throwExceptionOnRequestMatchMiss

When a request fails to match a mock, throws an exception. This will allow your test framework to fail a test and fix the problem before it's pushed to production. Set to true to activate this functionality.

The default value is false.

I know such feature exists in MSW (Mocked Server Worker) and other solutions for mocking requests at the network layer. It would be a nice addition to the MockedProvider.

@jerelmiller jerelmiller added the 🧪 testing Feature requests related to testing label Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧪 testing Feature requests related to testing
Projects
None yet
Development

No branches or pull requests

2 participants