Skip to content

Commit ef2eb66

Browse files
authored
test(vue-query/useMutation): add test for 'throw' from error watcher when 'throwOnError' returns true (#10239)
1 parent eca0da2 commit ef2eb66

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

packages/vue-query/src/__tests__/useMutation.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,5 +420,27 @@ describe('useMutation', () => {
420420
expect(boundaryFn).toHaveBeenCalledTimes(1)
421421
expect(boundaryFn).toHaveBeenCalledWith(err)
422422
})
423+
424+
test('should throw from error watcher when throwOnError returns true', async () => {
425+
const throwOnErrorFn = vi.fn().mockReturnValue(true)
426+
const { mutate } = useMutation({
427+
mutationFn: () =>
428+
sleep(10).then(() => Promise.reject(new Error('Some error'))),
429+
throwOnError: throwOnErrorFn,
430+
})
431+
432+
mutate()
433+
434+
// Suppress the Unhandled Rejection caused by watcher throw in Vue 3
435+
const rejectionHandler = () => {}
436+
process.on('unhandledRejection', rejectionHandler)
437+
438+
await vi.advanceTimersByTimeAsync(10)
439+
440+
process.off('unhandledRejection', rejectionHandler)
441+
442+
expect(throwOnErrorFn).toHaveBeenCalledTimes(1)
443+
expect(throwOnErrorFn).toHaveBeenCalledWith(Error('Some error'))
444+
})
423445
})
424446
})

0 commit comments

Comments
 (0)