Skip to content

Commit

Permalink
test(util): swallow expected error in observable hook factory test
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Aug 16, 2022
1 parent 3d8519e commit f322c7e
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ describe('createHookFromObservableFactory', () => {
})

it('bubbles errors throws in the observable factory', async () => {
// Error is hoisted. To prevent it from being printed as uncaught in terminal,
// we explicitly catch it and suppress it, recording that it has been called.
const preventer = jest.fn((evt: ErrorEvent) => evt.preventDefault())
if (typeof window !== 'undefined') {
window.addEventListener('error', preventer, false)
}

const observableFactory = () =>
Rx.from(
tick().then(() => {
Expand All @@ -86,5 +93,10 @@ describe('createHookFromObservableFactory', () => {
await waitForNextUpdate()

expect(result.error?.message).toBe('test error')

if (typeof window !== 'undefined') {
window.removeEventListener('error', preventer, false)
expect(preventer).toHaveBeenCalled()
}
})
})

0 comments on commit f322c7e

Please sign in to comment.