Skip to content

Commit

Permalink
✅ add more tests around uncaught errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed Jul 21, 2023
1 parent 20c9df2 commit 093e058
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/worker/src/boot/startWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,38 @@ describe('startWorker', () => {
streamId: undefined,
})
})

it('reports an error when an unexpected exception occurs while writing on a stream', () => {
if (!window.TextEncoder) {
pending('No TextEncoder support')
}
spyOn(TextEncoder.prototype, 'encode').and.callFake(() => {
throw new Error('Something went wrong!')
})
expect(
emulateAction({
id: 2,
streamId: TEST_STREAM_ID,
action: 'write',
data: 'baz',
})
).toEqual({
type: 'errored',
error: new Error('Something went wrong!'),
streamId: TEST_STREAM_ID,
})
})

it('use the string representation of the error when it fails to send it through postMessage', () => {
workerScope.postMessage.and.callFake((response) => {
if (response.type === 'errored' && response.error instanceof Error) {
throw new DOMException("Failed to execute 'postMessage' on 'WorkerScope'")
}
})
expect(emulateAction(null as any)).toEqual({
type: 'errored',
error: jasmine.stringContaining('TypeError'),
streamId: undefined,
})
})
})

0 comments on commit 093e058

Please sign in to comment.