jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

errors are being swallowed and converted to error events #51

Closed jameslnewell closed 6 years ago

jameslnewell commented 6 years ago

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 6 years ago