Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/__tests__/02.extra-3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import {alfredTip} from '@kentcdodds/react-workshop-app/test-utils'
import {render, screen} from '@testing-library/react'
import {render, screen, act} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import App from '../final/02.extra-3'
// import App from '../exercise/02'
Expand Down Expand Up @@ -56,15 +56,18 @@ test('displays the pokemon', async () => {
)
expect(console.error).toHaveBeenCalledTimes(2)

console.error.mockReset()
// restore the original implementation
console.error.mockRestore()
// but we still want to make sure it's not called
jest.spyOn(console, 'error')

userEvent.type(input, 'mew')
userEvent.click(submit)

// verify unmounting does not result in an error
unmount()
// wait for a bit for the mocked request to resolve:
await new Promise(r => setTimeout(r, 100))
await act(() => new Promise(r => setTimeout(r, 100)))
alfredTip(
() => expect(console.error).not.toHaveBeenCalled(),
'Make sure that when the component is unmounted the component does not attempt to trigger a rerender with `dispatch`',
Expand Down