Open History to see the last commit
1import {
2 cleanup,
3 render,
4 fireEvent,
5 waitFor,
6} from '@testing-library/react'
7import * as React from 'react'
8β
9import { setConsole, useMutation } from '../index'
10import { deepEqual } from '../utils'
11β
12describe('setConsole', () => {
13 afterEach(cleanup)
14β
15 it('should override Console object', async () => {
16 const mockConsole = {
17 error: jest.fn(),
18 }
19β
20 setConsole(mockConsole)
21β
22 function Page() {
23 const [mutate, { error }] = useMutation(() => {
24 throw new Error('Expected mock error. All is well!')
25 })
26β
27 return (
28 <div>
29 {error && <h1 data-testid="error">{error.message}</h1>}
30 <button onClick={mutate}>mutate</button>
31 </div>
32 )
33 }
34β
35 const { getByTestId, getByText } = render(<Page />)
36β
37 fireEvent.click(getByText('mutate'))
38β
39 await waitFor(() => getByTestId('error'))
40β
41 expect(mockConsole.error).toHaveBeenCalled()
42β
43 setConsole(console)
44 })
45})
46β
47describe('deepEqual', () => {
48 it('should return `false` for different dates', () => {
49 const date1 = new Date(2020, 3, 1)
50 const date2 = new Date(2020, 3, 2)
51β
52 expect(deepEqual(date1, date2)).toEqual(false)
53 })
54β
55 it('should return `true` for equal dates', () => {
56 const date1 = new Date(2020, 3, 1)
57 const date2 = new Date(2020, 3, 1)
58β
59 expect(deepEqual(date1, date2)).toEqual(true)
60 })
61})