Skip to content

Commit 97b5a99

Browse files
authored
Merge branch 'main' into feature/update-contributing-documentation
2 parents 9ce1d07 + 6e6bf85 commit 97b5a99

File tree

11 files changed

+76
-72
lines changed

11 files changed

+76
-72
lines changed

.codesandbox/ci.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"sandboxes": ["new", "github/kentcdodds/react-testing-library-examples"]
2+
"sandboxes": ["new", "github/kentcdodds/react-testing-library-examples"],
3+
"node": "12"
34
}

.github/workflows/validate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
if: ${{ !contains(github.head_ref, 'all-contributors') }}
1818
strategy:
1919
matrix:
20-
node: [10.13, 12, 14, 16]
20+
node: [12, 14, 16]
2121
react: [latest, next, experimental]
2222
runs-on: ubuntu-latest
2323
steps:

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "types/index.d.ts",
77
"module": "dist/@testing-library/react.esm.js",
88
"engines": {
9-
"node": ">=10"
9+
"node": ">=12"
1010
},
1111
"scripts": {
1212
"prebuild": "rimraf dist",
@@ -44,13 +44,13 @@
4444
"license": "MIT",
4545
"dependencies": {
4646
"@babel/runtime": "^7.12.5",
47-
"@testing-library/dom": "^7.28.1"
47+
"@testing-library/dom": "^8.0.0"
4848
},
4949
"devDependencies": {
5050
"@testing-library/jest-dom": "^5.11.6",
5151
"@types/react-dom": "^17.0.0",
5252
"dotenv-cli": "^4.0.0",
53-
"kcd-scripts": "^7.5.1",
53+
"kcd-scripts": "^11.1.0",
5454
"npm-run-all": "^4.1.5",
5555
"react": "^17.0.1",
5656
"react-dom": "^17.0.1",
@@ -68,7 +68,10 @@
6868
"react/no-adjacent-inline-elements": "off",
6969
"import/no-unassigned-import": "off",
7070
"import/named": "off",
71-
"testing-library/no-dom-import": "off"
71+
"testing-library/no-container": "off",
72+
"testing-library/no-dom-import": "off",
73+
"testing-library/no-unnecessary-act": "off",
74+
"testing-library/prefer-user-event": "off"
7275
}
7376
},
7477
"eslintIgnore": [

src/__tests__/cleanup.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ describe('fake timers and missing act warnings', () => {
5454
jest.useRealTimers()
5555
})
5656

57-
test('cleanup does not flush immediates', () => {
57+
test('cleanup does not flush microtasks', () => {
5858
const microTaskSpy = jest.fn()
5959
function Test() {
6060
const counter = 1
6161
const [, setDeferredCounter] = React.useState(null)
6262
React.useEffect(() => {
6363
let cancelled = false
64-
setImmediate(() => {
64+
Promise.resolve().then(() => {
6565
microTaskSpy()
66+
// eslint-disable-next-line jest/no-if -- false positive
6667
if (!cancelled) {
6768
setDeferredCounter(counter)
6869
}
@@ -95,12 +96,12 @@ describe('fake timers and missing act warnings', () => {
9596
const [, setDeferredCounter] = React.useState(null)
9697
React.useEffect(() => {
9798
let cancelled = false
98-
setImmediate(() => {
99+
setTimeout(() => {
99100
deferredStateUpdateSpy()
100101
if (!cancelled) {
101102
setDeferredCounter(counter)
102103
}
103-
})
104+
}, 0)
104105

105106
return () => {
106107
cancelled = true
@@ -111,7 +112,7 @@ describe('fake timers and missing act warnings', () => {
111112
}
112113
render(<Test />)
113114

114-
jest.runAllImmediates()
115+
jest.runAllTimers()
115116
cleanup()
116117

117118
expect(deferredStateUpdateSpy).toHaveBeenCalledTimes(1)

src/__tests__/debug.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ test('allows same arguments as prettyDOM', () => {
4343
expect(console.log).toHaveBeenCalledTimes(1)
4444
expect(console.log.mock.calls[0]).toMatchInlineSnapshot(`
4545
Array [
46-
"<div>
47-
...",
46+
<div>
47+
...,
4848
]
4949
`)
5050
})

src/__tests__/new-act.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let asyncAct
1+
let asyncAct, consoleErrorMock
22

33
jest.mock('react-dom/test-utils', () => ({
44
act: cb => {
@@ -9,11 +9,11 @@ jest.mock('react-dom/test-utils', () => ({
99
beforeEach(() => {
1010
jest.resetModules()
1111
asyncAct = require('../act-compat').asyncAct
12-
jest.spyOn(console, 'error').mockImplementation(() => {})
12+
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
1313
})
1414

1515
afterEach(() => {
16-
console.error.mockRestore()
16+
consoleErrorMock.mockRestore()
1717
})
1818

1919
test('async act works when it does not exist (older versions of react)', async () => {
@@ -49,7 +49,7 @@ test('async act recovers from errors', async () => {
4949
expect(console.error.mock.calls).toMatchInlineSnapshot(`
5050
Array [
5151
Array [
52-
"call console.error",
52+
call console.error,
5353
],
5454
]
5555
`)
@@ -67,7 +67,7 @@ test('async act recovers from sync errors', async () => {
6767
expect(console.error.mock.calls).toMatchInlineSnapshot(`
6868
Array [
6969
Array [
70-
"call console.error",
70+
call console.error,
7171
],
7272
]
7373
`)

src/__tests__/no-act.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
let act, asyncAct, React
1+
let act, asyncAct, React, consoleErrorMock
22

33
beforeEach(() => {
44
jest.resetModules()
5-
act = require('..').act
5+
act = require('../pure').act
66
asyncAct = require('../act-compat').asyncAct
77
React = require('react')
8-
jest.spyOn(console, 'error').mockImplementation(() => {})
8+
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
99
})
1010

1111
afterEach(() => {
12-
console.error.mockRestore()
12+
consoleErrorMock.mockRestore()
1313
})
1414

1515
jest.mock('react-dom/test-utils', () => ({}))
@@ -83,7 +83,7 @@ test('async act recovers from sync errors', async () => {
8383
expect(console.error.mock.calls).toMatchInlineSnapshot(`
8484
Array [
8585
Array [
86-
"call console.error",
86+
call console.error,
8787
],
8888
]
8989
`)

src/__tests__/old-act.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
let asyncAct
1+
let asyncAct, consoleErrorMock
22

33
beforeEach(() => {
44
jest.resetModules()
55
asyncAct = require('../act-compat').asyncAct
6-
jest.spyOn(console, 'error').mockImplementation(() => {})
6+
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
77
})
88

99
afterEach(() => {
10-
console.error.mockRestore()
10+
consoleErrorMock.mockRestore()
1111
})
1212

1313
jest.mock('react-dom/test-utils', () => ({
@@ -32,18 +32,18 @@ test('async act works even when the act is an old one', async () => {
3232
console.error('sigil')
3333
})
3434
expect(console.error.mock.calls).toMatchInlineSnapshot(`
35-
Array [
36-
Array [
37-
"sigil",
38-
],
39-
Array [
40-
"It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least [email protected] to remove this warning.",
41-
],
42-
Array [
43-
"sigil",
44-
],
45-
]
46-
`)
35+
Array [
36+
Array [
37+
sigil,
38+
],
39+
Array [
40+
It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least [email protected] to remove this warning.,
41+
],
42+
Array [
43+
sigil,
44+
],
45+
]
46+
`)
4747
expect(callback).toHaveBeenCalledTimes(1)
4848

4949
// and it doesn't warn you twice
@@ -71,10 +71,10 @@ test('async act recovers from async errors', async () => {
7171
expect(console.error.mock.calls).toMatchInlineSnapshot(`
7272
Array [
7373
Array [
74-
"It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least [email protected] to remove this warning.",
74+
It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least [email protected] to remove this warning.,
7575
],
7676
Array [
77-
"call console.error",
77+
call console.error,
7878
],
7979
]
8080
`)
@@ -92,7 +92,7 @@ test('async act recovers from sync errors', async () => {
9292
expect(console.error.mock.calls).toMatchInlineSnapshot(`
9393
Array [
9494
Array [
95-
"call console.error",
95+
call console.error,
9696
],
9797
]
9898
`)
@@ -109,11 +109,11 @@ test('async act can handle any sort of console.error', async () => {
109109
Array [
110110
Array [
111111
Object {
112-
"error": "some error",
112+
error: some error,
113113
},
114114
],
115115
Array [
116-
"It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least [email protected] to remove this warning.",
116+
It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least [email protected] to remove this warning.,
117117
],
118118
]
119119
`)

src/__tests__/render.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ test('renders options.wrapper around node', () => {
7878

7979
expect(screen.getByTestId('wrapper')).toBeInTheDocument()
8080
expect(container.firstChild).toMatchInlineSnapshot(`
81-
<div
82-
data-testid="wrapper"
83-
>
84-
<div
85-
data-testid="inner"
86-
/>
87-
</div>
88-
`)
81+
<div
82+
data-testid=wrapper
83+
>
84+
<div
85+
data-testid=inner
86+
/>
87+
</div>
88+
`)
8989
})
9090

9191
test('flushes useEffect cleanup functions sync on unmount()', () => {

tests/setup-env.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import '@testing-library/jest-dom/extend-expect'
22

3+
let consoleErrorMock
4+
35
beforeEach(() => {
46
const originalConsoleError = console.error
5-
jest
7+
consoleErrorMock = jest
68
.spyOn(console, 'error')
79
.mockImplementation((message, ...optionalParams) => {
810
// Ignore ReactDOM.render/ReactDOM.hydrate deprecation warning
@@ -14,8 +16,5 @@ beforeEach(() => {
1416
})
1517

1618
afterEach(() => {
17-
// maybe another test already restore console error mocks
18-
if (typeof console.error.mockRestore === 'function') {
19-
console.error.mockRestore()
20-
}
19+
consoleErrorMock.mockRestore()
2120
})

types/test.tsx

+16-16
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@ import {render, fireEvent, screen, waitFor} from '.'
33
import * as pure from './pure'
44

55
export async function testRender() {
6-
const page = render(<button />)
6+
const view = render(<button />)
77

88
// single queries
9-
page.getByText('foo')
10-
page.queryByText('foo')
11-
await page.findByText('foo')
9+
view.getByText('foo')
10+
view.queryByText('foo')
11+
await view.findByText('foo')
1212

1313
// multiple queries
14-
page.getAllByText('bar')
15-
page.queryAllByText('bar')
16-
await page.findAllByText('bar')
14+
view.getAllByText('bar')
15+
view.queryAllByText('bar')
16+
await view.findAllByText('bar')
1717

1818
// helpers
19-
const {container, rerender, debug} = page
19+
const {container, rerender, debug} = view
2020
expectType<HTMLElement, typeof container>(container)
2121
return {container, rerender, debug}
2222
}
2323

2424
export async function testPureRender() {
25-
const page = pure.render(<button />)
25+
const view = pure.render(<button />)
2626

2727
// single queries
28-
page.getByText('foo')
29-
page.queryByText('foo')
30-
await page.findByText('foo')
28+
view.getByText('foo')
29+
view.queryByText('foo')
30+
await view.findByText('foo')
3131

3232
// multiple queries
33-
page.getAllByText('bar')
34-
page.queryAllByText('bar')
35-
await page.findAllByText('bar')
33+
view.getAllByText('bar')
34+
view.queryAllByText('bar')
35+
await view.findAllByText('bar')
3636

3737
// helpers
38-
const {container, rerender, debug} = page
38+
const {container, rerender, debug} = view
3939
expectType<HTMLElement, typeof container>(container)
4040
return {container, rerender, debug}
4141
}

0 commit comments

Comments
 (0)