Use @testing-library instead of react-dom/test-utils (#65328)

Closes NEXT-3313
This commit is contained in:
Sebastian Silbermann 2024-05-06 21:02:25 +02:00 committed by GitHub
parent 44a21f4cc2
commit 79afd61da5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,38 +2,16 @@
* @jest-environment jsdom
*/
import React from 'react'
// eslint-disable-next-line react/no-deprecated
import { render, unmountComponentAtNode } from 'react-dom'
import { act } from 'react-dom/test-utils'
import { render } from '@testing-library/react'
import Hello from '../components/hello'
describe('Link without a router', () => {
let container = null
beforeEach(() => {
container = document.createElement('div')
document.body.appendChild(container)
})
afterEach(() => {
unmountComponentAtNode(container)
container.remove()
container = null
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('should not throw when rendered', () => {
jest.useFakeTimers()
act(() => {
render(<Hello />, container)
})
act(() => {
jest.runAllTimers()
})
const { container } = render(<Hello />)
expect(container.textContent).toBe('Click me')
})
@ -44,15 +22,7 @@ describe('Link without a router', () => {
() => {
// eslint-disable-next-line jest/no-identical-title
it('should not throw when rendered', () => {
jest.useFakeTimers()
act(() => {
render(<Hello />, container)
})
act(() => {
jest.runAllTimers()
})
const { container } = render(<Hello />)
expect(container.textContent).toBe('Click me')
})