errors are being swallowed and converted to error events
jameslnewell opened this issue · 1 comments
jameslnewell commented
making it really hard to debug when devs didn't actually intend to throw an error.
I think its happening in https://github.com/jameslnewell/xhr-mock/blob/master/packages/xhr-mock/src/MockXMLHttpRequest.ts#L523
Note: we probably don't want to log errors when they are intended (and fill up logs/false positives).
it('oops', async () => {
mock.post('/api/user', () => {
throw new Error('oops');
});
try {
const user = await createUser({name: 'John'});
} catch (error) {
// no idea what the user did wrong in their mock
expect(error).toMatch('A user named "John" already exists.');
}
})
jameslnewell commented
- mock.error(handler)
- mock.on('error', handler)
- mock.use((req, res, err) => console.log(err))
- mock.setLogMethod(console.log)
- ...
- always console log it?