Commit 693761fb authored by Robert Knight's avatar Robert Knight

Test `sendError` directly

Previously `sendError` was tested indirectly via captureErrors. However
since this is exported as an API from the module, it makes sense to test
it directly.
parent 36b0bda5
...@@ -53,16 +53,26 @@ describe('shared/frame-error-capture', () => { ...@@ -53,16 +53,26 @@ describe('shared/frame-error-capture', () => {
type: 'hypothesis-error', type: 'hypothesis-error',
}); });
}); });
});
it('does not forward errors if there is no handler frame', () => { describe('sendError', () => {
const callback = captureErrors(() => { it('sends error to handler frame', async () => {
throw new Error('Test error'); sendErrorsTo(window);
}, 'Testing captureErrors'); sendError(new Error('Test error'), 'some context');
assert.throws(() => { await delay(0);
callback();
}, 'Test error');
assert.equal(errorEvents.length, 1);
assert.match(errorEvents[0], {
context: 'some context',
error: sinon.match({ message: 'Test error' }),
type: 'hypothesis-error',
});
});
it('does not forward errors if there is no handler frame', async () => {
sendError(new Error('Test error'));
await delay(0);
assert.equal(errorEvents.length, 0); assert.equal(errorEvents.length, 0);
}); });
...@@ -74,13 +84,7 @@ describe('shared/frame-error-capture', () => { ...@@ -74,13 +84,7 @@ describe('shared/frame-error-capture', () => {
sinon.stub(console, 'warn'); sinon.stub(console, 'warn');
sendErrorsTo(window); sendErrorsTo(window);
const callback = captureErrors(() => { sendError(new Error('Test error'), 'some context');
throw new Error('Test error');
}, 'Testing captureErrors');
assert.throws(() => {
callback();
}, 'Test error');
assert.calledOnce(window.postMessage); assert.calledOnce(window.postMessage);
assert.calledOnce(console.warn); assert.calledOnce(console.warn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment