Skip to content

Commit ba4e95a

Browse files
committed
Fixed accidental removal of vitests unhandledRejection handler
1 parent 66c5e21 commit ba4e95a

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

packages/query-core/src/__tests__/mutations.test.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -844,10 +844,6 @@ describe('mutations', () => {
844844
})
845845

846846
describe('erroneous mutation callback', () => {
847-
afterEach(() => {
848-
process.removeAllListeners('unhandledRejection')
849-
})
850-
851847
test('error by global onSuccess triggers onError callback', async () => {
852848
const newMutationError = new Error('mutation-error')
853849

@@ -956,7 +952,9 @@ describe('mutations', () => {
956952
expect(mutationError).toEqual(newMutationError)
957953
})
958954

959-
test('error by global onSettled triggers onError callback, calling global onSettled callback twice', async () => {
955+
test('error by global onSettled triggers onError callback, calling global onSettled callback twice', async ({
956+
onTestFinished,
957+
}) => {
960958
const newMutationError = new Error('mutation-error')
961959

962960
queryClient = new QueryClient({
@@ -972,6 +970,9 @@ describe('mutations', () => {
972970

973971
const unhandledRejectionFn = vi.fn()
974972
process.on('unhandledRejection', (error) => unhandledRejectionFn(error))
973+
onTestFinished(() => {
974+
process.off('unhandledRejection', unhandledRejectionFn)
975+
})
975976

976977
const key = queryKey()
977978
const results: Array<string> = []
@@ -1025,9 +1026,14 @@ describe('mutations', () => {
10251026
expect(mutationError).toEqual(newMutationError)
10261027
})
10271028

1028-
test('error by mutations onSettled triggers onError callback, calling both onSettled callbacks twice', async () => {
1029+
test('error by mutations onSettled triggers onError callback, calling both onSettled callbacks twice', async ({
1030+
onTestFinished,
1031+
}) => {
10291032
const unhandledRejectionFn = vi.fn()
10301033
process.on('unhandledRejection', (error) => unhandledRejectionFn(error))
1034+
onTestFinished(() => {
1035+
process.off('unhandledRejection', unhandledRejectionFn)
1036+
})
10311037

10321038
const key = queryKey()
10331039
const results: Array<string> = []
@@ -1084,9 +1090,14 @@ describe('mutations', () => {
10841090
expect(mutationError).toEqual(newMutationError)
10851091
})
10861092

1087-
test('errors by onError and consecutive onSettled callbacks are transferred to different execution context where it are reported', async () => {
1093+
test('errors by onError and consecutive onSettled callbacks are transferred to different execution context where it are reported', async ({
1094+
onTestFinished,
1095+
}) => {
10881096
const unhandledRejectionFn = vi.fn()
10891097
process.on('unhandledRejection', (error) => unhandledRejectionFn(error))
1098+
onTestFinished(() => {
1099+
process.off('unhandledRejection', unhandledRejectionFn)
1100+
})
10901101

10911102
const globalErrorError = new Error('global-error-error')
10921103
const globalSettledError = new Error('global-settled-error')

packages/react-query/src/__tests__/useMutation.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,10 +1067,11 @@ describe('useMutation', () => {
10671067
it('should go to error state if onError callback errors', async ({
10681068
onTestFinished,
10691069
}) => {
1070+
const unhandledRejectionFn = vi.fn()
1071+
process.on('unhandledRejection', (error) => unhandledRejectionFn(error))
10701072
onTestFinished(() => {
1071-
process.removeAllListeners('unhandledRejection')
1073+
process.off('unhandledRejection', unhandledRejectionFn)
10721074
})
1073-
process.on('unhandledRejection', vi.fn())
10741075

10751076
const error = new Error('error from onError')
10761077
const mutateFnError = new Error('mutateFnError')
@@ -1111,10 +1112,11 @@ describe('useMutation', () => {
11111112
it('should go to error state if onSettled callback errors', async ({
11121113
onTestFinished,
11131114
}) => {
1115+
const unhandledRejectionFn = vi.fn()
1116+
process.on('unhandledRejection', (error) => unhandledRejectionFn(error))
11141117
onTestFinished(() => {
1115-
process.removeAllListeners('unhandledRejection')
1118+
process.off('unhandledRejection', unhandledRejectionFn)
11161119
})
1117-
process.on('unhandledRejection', vi.fn())
11181120

11191121
const error = new Error('error from onSettled')
11201122
const mutateFnError = new Error('mutateFnError')

packages/solid-query/src/__tests__/useMutation.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,11 @@ describe('useMutation', () => {
11211121
it('should go to error state if onError callback errors', async ({
11221122
onTestFinished,
11231123
}) => {
1124+
const unhandledRejectionFn = vi.fn()
1125+
process.on('unhandledRejection', (error) => unhandledRejectionFn(error))
11241126
onTestFinished(() => {
1125-
process.removeAllListeners('unhandledRejection')
1127+
process.off('unhandledRejection', unhandledRejectionFn)
11261128
})
1127-
process.on('unhandledRejection', vi.fn())
11281129

11291130
const error = new Error('error from onError')
11301131
const mutateFnError = new Error('mutateFnError')
@@ -1169,10 +1170,11 @@ describe('useMutation', () => {
11691170
it('should go to error state if onSettled callback errors', async ({
11701171
onTestFinished,
11711172
}) => {
1173+
const unhandledRejectionFn = vi.fn()
1174+
process.on('unhandledRejection', (error) => unhandledRejectionFn(error))
11721175
onTestFinished(() => {
1173-
process.removeAllListeners('unhandledRejection')
1176+
process.off('unhandledRejection', unhandledRejectionFn)
11741177
})
1175-
process.on('unhandledRejection', vi.fn())
11761178

11771179
const error = new Error('error from onSettled')
11781180
const mutateFnError = new Error('mutateFnError')

0 commit comments

Comments
 (0)