sinonjs / nise

Fake XHR and fake server
Other
109 stars 47 forks source link

Is there a way to catch non-mocked responses? #189

Closed hornta closed 1 month ago

hornta commented 3 years ago

I've setup my test suite to mock every response my application performs to our REST API but I feel like it's common to forget to mock some API:s so I would want a way for our tests to fail when a non-mocked API is called upon. Is something like that possible with nise/sinon?

fatso83 commented 3 years ago

Not that I can think of immediately, but this is kind of like a catch-all if no other. Would be interesting to have this feature. Can you have a little browse of the (not very big) source code and see if the match code can be made to do this? Maybe it can accept a function or something.

hornta commented 3 years ago

The fakeserver can take a catch-all response but it doesn't help me being able to throw when that response is matched. I tend to use https://mswjs.io/ in other projects so inspiration can be taken from there https://mswjs.io/docs/recipes/debugging-uncaught-requests

Maybe the fakeserver can emit an event like "onUnhandledRequest"?

stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.