axios-mock-adapter
axios-mock-adapter copied to clipboard
Possible to throw an error if a request was made but not mocked?
I've used other mocking libraries in the past with other languages. One of the features I really miss is the ability to have my mocking library make my test fail if a request was made, but not mocked.
Ideally, axios-mock-adapter
would report the request that was made, but not mocked, so that I could either:
- Add an appropriate mock
- Fix my code so that this unexpected axios call no longer happens.
Is this currently possible with axios-mock-adapter
?
I think this would achieve what you're after:
// Register this as the last handler, which will catch any unmatched request
mock.onAny().reply(function(config) {
throw new Error('Could not find mock for ' + config.url);
});
instance.get('/foo');
It would of course be more convenient if this could be defined when the mock is created, but there's no support for that yet.