Open History to see the last commit
1import { queryKey, mockConsoleError } from '../../react/tests/utils'
2import { MutationCache, QueryClient } from '../..'
3β
4describe('mutationCache', () => {
5 describe('MutationCacheConfig.onError', () => {
6 test('should be called when a mutation errors', async () => {
7 const consoleMock = mockConsoleError()
8 const key = queryKey()
9 const onError = jest.fn()
10 const testCache = new MutationCache({ onError })
11 const testClient = new QueryClient({ mutationCache: testCache })
12β
13 try {
14 await testClient.executeMutation({
15 mutationKey: key,
16 variables: 'vars',
17 mutationFn: () => Promise.reject('error'),
18 onMutate: () => 'context',
19 })
20 } catch {
21 consoleMock.mockRestore()
22 }
23β
24 const mutation = testCache.getAll()[0]
25 expect(onError).toHaveBeenCalledWith('error', 'vars', 'context', mutation)
26 })
27 })
28})