Skip to content

Commit 6a14455

Browse files
authored
Merge branch 'main' into improve-render-options-jsdocs
2 parents fd7dbd8 + 8f3bd3c commit 6a14455

17 files changed

+168
-91
lines changed

.all-contributorsrc

+27
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,33 @@
12521252
"contributions": [
12531253
"test"
12541254
]
1255+
},
1256+
{
1257+
"login": "jhnns",
1258+
"name": "Johannes Ewald",
1259+
"avatar_url": "https://avatars.githubusercontent.com/u/781746?v=4",
1260+
"profile": "https://github.com/jhnns",
1261+
"contributions": [
1262+
"code"
1263+
]
1264+
},
1265+
{
1266+
"login": "anpaopao",
1267+
"name": "Angus J. Pope",
1268+
"avatar_url": "https://avatars.githubusercontent.com/u/44686792?v=4",
1269+
"profile": "https://github.com/anpaopao",
1270+
"contributions": [
1271+
"doc"
1272+
]
1273+
},
1274+
{
1275+
"login": "leschdom",
1276+
"name": "Dominik Lesch",
1277+
"avatar_url": "https://avatars.githubusercontent.com/u/62334278?v=4",
1278+
"profile": "https://github.com/leschdom",
1279+
"contributions": [
1280+
"doc"
1281+
]
12551282
}
12561283
],
12571284
"contributorsPerLine": 7,

.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/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ merge of your pull request!
3737
- [ ] Documentation added to the
3838
[docs site](https://github.com/testing-library/testing-library-docs)
3939
- [ ] Tests
40-
- [ ] Typescript definitions updated
40+
- [ ] TypeScript definitions updated
4141
- [ ] Ready to be merged
4242
<!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
4343

.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, 15, 16]
20+
node: [12, 14, 16]
2121
react: [latest, next, experimental]
2222
runs-on: ubuntu-latest
2323
steps:

CONTRIBUTING.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ sure to include those changes (if they exist) in your commit.
3535
### Update Typings
3636
3737
If your PR introduced some changes in the API, you are more than welcome to
38-
modify the Typescript type definition to reflect those changes. Just modify the
39-
`/types/index.d.ts` file accordingly. If you have never seen Typescript
38+
modify the TypeScript type definition to reflect those changes. Just modify the
39+
`/types/index.d.ts` file accordingly. If you have never seen TypeScript
4040
definitions before, you can read more about it in its
4141
[documentation pages](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html).
42-
Though this library itself is not written in Typescript we use
42+
Though this library itself is not written in TypeScript we use
4343
[dtslint](https://github.com/microsoft/dtslint) to lint our typings.
4444
4545
## Help needed
@@ -50,6 +50,5 @@ Also, please watch the repo and respond to questions/bug reports/feature
5050
requests! Thanks!
5151
5252
[egghead]:
53-
https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github
54-
[all-contributors]: https://github.com/all-contributors/all-contributors
53+
https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github
5554
[issues]: https://github.com/testing-library/react-testing-library/issues

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ Thanks goes to these people ([emoji key][emojis]):
607607
<td align="center"><a href="https://github.com/sanchit121"><img src="https://avatars2.githubusercontent.com/u/30828115?v=4?s=100" width="100px;" alt=""/><br /><sub><b>sanchit121</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/issues?q=author%3Asanchit121" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/react-testing-library/commits?author=sanchit121" title="Code">💻</a></td>
608608
<td align="center"><a href="https://github.com/solufa"><img src="https://avatars.githubusercontent.com/u/9402912?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Solufa</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/issues?q=author%3Asolufa" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/react-testing-library/commits?author=solufa" title="Code">💻</a></td>
609609
<td align="center"><a href="https://codepen.io/ariperkkio/"><img src="https://avatars.githubusercontent.com/u/14806298?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ari Perkkiö</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=AriPerkkio" title="Tests">⚠️</a></td>
610+
<td align="center"><a href="https://github.com/jhnns"><img src="https://avatars.githubusercontent.com/u/781746?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Johannes Ewald</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=jhnns" title="Code">💻</a></td>
611+
<td align="center"><a href="https://github.com/anpaopao"><img src="https://avatars.githubusercontent.com/u/44686792?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Angus J. Pope</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=anpaopao" title="Documentation">📖</a></td>
612+
<td align="center"><a href="https://github.com/leschdom"><img src="https://avatars.githubusercontent.com/u/62334278?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dominik Lesch</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=leschdom" title="Documentation">📖</a></td>
610613
</tr>
611614
</table>
612615

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

+20-10
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
}
@@ -82,7 +83,10 @@ describe('fake timers and missing act warnings', () => {
8283
expect(microTaskSpy).toHaveBeenCalledTimes(0)
8384
// console.error is mocked
8485
// eslint-disable-next-line no-console
85-
expect(console.error).toHaveBeenCalledTimes(0)
86+
expect(console.error).toHaveBeenCalledTimes(
87+
// ReactDOM.render is deprecated in React 18
88+
React.version.startsWith('18') ? 1 : 0,
89+
)
8690
})
8791

8892
test('cleanup does not swallow missing act warnings', () => {
@@ -92,12 +96,12 @@ describe('fake timers and missing act warnings', () => {
9296
const [, setDeferredCounter] = React.useState(null)
9397
React.useEffect(() => {
9498
let cancelled = false
95-
setImmediate(() => {
99+
setTimeout(() => {
96100
deferredStateUpdateSpy()
97101
if (!cancelled) {
98102
setDeferredCounter(counter)
99103
}
100-
})
104+
}, 0)
101105

102106
return () => {
103107
cancelled = true
@@ -108,16 +112,22 @@ describe('fake timers and missing act warnings', () => {
108112
}
109113
render(<Test />)
110114

111-
jest.runAllImmediates()
115+
jest.runAllTimers()
112116
cleanup()
113117

114118
expect(deferredStateUpdateSpy).toHaveBeenCalledTimes(1)
115119
// console.error is mocked
116120
// eslint-disable-next-line no-console
117-
expect(console.error).toHaveBeenCalledTimes(1)
118-
// eslint-disable-next-line no-console
119-
expect(console.error.mock.calls[0][0]).toMatch(
120-
'a test was not wrapped in act(...)',
121+
expect(console.error).toHaveBeenCalledTimes(
122+
// ReactDOM.render is deprecated in React 18
123+
React.version.startsWith('18') ? 2 : 1,
121124
)
125+
// eslint-disable-next-line no-console
126+
expect(
127+
console.error.mock.calls[
128+
// ReactDOM.render is deprecated in React 18
129+
React.version.startsWith('18') ? 1 : 0
130+
][0],
131+
).toMatch('a test was not wrapped in act(...)')
122132
})
123133
})

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

+28-16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
let act, asyncAct
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
7-
jest.spyOn(console, 'error').mockImplementation(() => {})
7+
React = require('react')
8+
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
89
})
910

1011
afterEach(() => {
11-
console.error.mockRestore()
12+
consoleErrorMock.mockRestore()
1213
})
1314

1415
jest.mock('react-dom/test-utils', () => ({}))
@@ -17,7 +18,10 @@ test('act works even when there is no act from test utils', () => {
1718
const callback = jest.fn()
1819
act(callback)
1920
expect(callback).toHaveBeenCalledTimes(1)
20-
expect(console.error).toHaveBeenCalledTimes(0)
21+
expect(console.error).toHaveBeenCalledTimes(
22+
// ReactDOM.render is deprecated in React 18
23+
React.version.startsWith('18') ? 1 : 0,
24+
)
2125
})
2226

2327
test('async act works when it does not exist (older versions of react)', async () => {
@@ -26,7 +30,10 @@ test('async act works when it does not exist (older versions of react)', async (
2630
await Promise.resolve()
2731
await callback()
2832
})
29-
expect(console.error).toHaveBeenCalledTimes(0)
33+
expect(console.error).toHaveBeenCalledTimes(
34+
// ReactDOM.render is deprecated in React 18
35+
React.version.startsWith('18') ? 2 : 0,
36+
)
3037
expect(callback).toHaveBeenCalledTimes(1)
3138

3239
callback.mockClear()
@@ -36,7 +43,10 @@ test('async act works when it does not exist (older versions of react)', async (
3643
await Promise.resolve()
3744
await callback()
3845
})
39-
expect(console.error).toHaveBeenCalledTimes(0)
46+
expect(console.error).toHaveBeenCalledTimes(
47+
// ReactDOM.render is deprecated in React 18
48+
React.version.startsWith('18') ? 2 : 0,
49+
)
4050
expect(callback).toHaveBeenCalledTimes(1)
4151
})
4252

@@ -49,14 +59,16 @@ test('async act recovers from errors', async () => {
4959
} catch (err) {
5060
console.error('call console.error')
5161
}
52-
expect(console.error).toHaveBeenCalledTimes(1)
53-
expect(console.error.mock.calls).toMatchInlineSnapshot(`
54-
Array [
55-
Array [
56-
"call console.error",
57-
],
58-
]
59-
`)
62+
expect(console.error).toHaveBeenCalledTimes(
63+
// ReactDOM.render is deprecated in React 18
64+
React.version.startsWith('18') ? 2 : 1,
65+
)
66+
expect(
67+
console.error.mock.calls[
68+
// ReactDOM.render is deprecated in React 18
69+
React.version.startsWith('18') ? 1 : 0
70+
][0],
71+
).toMatch('call console.error')
6072
})
6173

6274
test('async act recovers from sync errors', async () => {
@@ -71,7 +83,7 @@ test('async act recovers from sync errors', async () => {
7183
expect(console.error.mock.calls).toMatchInlineSnapshot(`
7284
Array [
7385
Array [
74-
"call console.error",
86+
call console.error,
7587
],
7688
]
7789
`)

0 commit comments

Comments
 (0)