Skip to content

Commit 88f44fe

Browse files
authored
Merge branch 'main' into feat/renderHooks
2 parents 887d95b + ccd8a0d commit 88f44fe

18 files changed

+411
-450
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,16 @@
12971297
"contributions": [
12981298
"bug"
12991299
]
1300+
},
1301+
{
1302+
"login": "fmeum",
1303+
"name": "Fabian Meumertzheim",
1304+
"avatar_url": "https://avatars.githubusercontent.com/u/4312191?v=4",
1305+
"profile": "https://hen.ne.ke",
1306+
"contributions": [
1307+
"code",
1308+
"bug"
1309+
]
13001310
}
13011311
],
13021312
"contributorsPerLine": 7,

.codesandbox/ci.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"installCommand": "install:csb",
23
"sandboxes": ["new", "github/kentcdodds/react-testing-library-examples"],
34
"node": "12"
45
}

.github/workflows/validate.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
# ignore all-contributors PRs
1717
if: ${{ !contains(github.head_ref, 'all-contributors') }}
1818
strategy:
19+
fail-fast: false
1920
matrix:
2021
# TODO: relax `'16.9.1'` to `16` once GitHub has 16.9.1 cached. 16.9.0 is broken due to https://github.com/nodejs/node/issues/40030
2122
node: [12, 14, '16.9.1']
@@ -52,6 +53,8 @@ jobs:
5253

5354
- name: ⬆️ Upload coverage report
5455
uses: codecov/codecov-action@v1
56+
with:
57+
flags: ${{ matrix.react }}
5558

5659
release:
5760
needs: main

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ Thanks goes to these people ([emoji key][emojis]):
614614
<tr>
615615
<td align="center"><a href="https://github.com/ImADrafter"><img src="https://avatars.githubusercontent.com/u/44379989?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Marcos Gómez</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=ImADrafter" title="Documentation">📖</a></td>
616616
<td align="center"><a href="https://www.akashshyam.online/"><img src="https://avatars.githubusercontent.com/u/56759828?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Akash Shyam</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/issues?q=author%3Aakashshyamdev" title="Bug reports">🐛</a></td>
617+
<td align="center"><a href="https://hen.ne.ke"><img src="https://avatars.githubusercontent.com/u/4312191?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fabian Meumertzheim</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=fmeum" title="Code">💻</a> <a href="https://github.com/testing-library/react-testing-library/issues?q=author%3Afmeum" title="Bug reports">🐛</a></td>
617618
</tr>
618619
</table>
619620

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"build:bundle:pure": "dotenv -e .bundle.main.env -e .bundle.pure.env kcd-scripts build -- --bundle --no-clean",
1616
"build:main": "kcd-scripts build --no-clean",
1717
"format": "kcd-scripts format",
18+
"install:csb": "npm install",
1819
"lint": "kcd-scripts lint",
1920
"setup": "npm install && npm run validate -s",
2021
"test": "kcd-scripts test",
@@ -45,22 +46,22 @@
4546
"license": "MIT",
4647
"dependencies": {
4748
"@babel/runtime": "^7.12.5",
48-
"@testing-library/dom": "^8.0.0"
49+
"@testing-library/dom": "^8.5.0",
50+
"@types/react-dom": "*"
4951
},
5052
"devDependencies": {
5153
"@testing-library/jest-dom": "^5.11.6",
52-
"@types/react-dom": "^17.0.0",
5354
"dotenv-cli": "^4.0.0",
5455
"kcd-scripts": "^11.1.0",
5556
"npm-run-all": "^4.1.5",
56-
"react": "^17.0.1",
57-
"react-dom": "^17.0.1",
57+
"react": "^18.0.0",
58+
"react-dom": "^18.0.0",
5859
"rimraf": "^3.0.2",
5960
"typescript": "^4.1.2"
6061
},
6162
"peerDependencies": {
62-
"react": "*",
63-
"react-dom": "*"
63+
"react": "^18.0.0",
64+
"react-dom": "^18.0.0"
6465
},
6566
"eslintConfig": {
6667
"extends": "./node_modules/kcd-scripts/eslint.js",

src/__tests__/act.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import {render, fireEvent, screen} from '../'
2+
import {act, render, fireEvent, screen} from '../'
33

44
test('render calls useEffect immediately', () => {
55
const effectCb = jest.fn()
@@ -43,3 +43,27 @@ test('calls to hydrate will run useEffects', () => {
4343
render(<MyUselessComponent />, {hydrate: true})
4444
expect(effectCb).toHaveBeenCalledTimes(1)
4545
})
46+
47+
test('cleans up IS_REACT_ACT_ENVIRONMENT if its callback throws', () => {
48+
global.IS_REACT_ACT_ENVIRONMENT = false
49+
50+
expect(() =>
51+
act(() => {
52+
throw new Error('threw')
53+
}),
54+
).toThrow('threw')
55+
56+
expect(global.IS_REACT_ACT_ENVIRONMENT).toEqual(false)
57+
})
58+
59+
test('cleans up IS_REACT_ACT_ENVIRONMENT if its async callback throws', async () => {
60+
global.IS_REACT_ACT_ENVIRONMENT = false
61+
62+
await expect(() =>
63+
act(async () => {
64+
throw new Error('thenable threw')
65+
}),
66+
).rejects.toThrow('thenable threw')
67+
68+
expect(global.IS_REACT_ACT_ENVIRONMENT).toEqual(false)
69+
})

src/__tests__/cleanup.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ describe('fake timers and missing act warnings', () => {
8383
expect(microTaskSpy).toHaveBeenCalledTimes(0)
8484
// console.error is mocked
8585
// eslint-disable-next-line no-console
86-
expect(console.error).toHaveBeenCalledTimes(
87-
// ReactDOM.render is deprecated in React 18
88-
React.version.startsWith('18') ? 1 : 0,
89-
)
86+
expect(console.error).toHaveBeenCalledTimes(0)
9087
})
9188

9289
test('cleanup does not swallow missing act warnings', () => {
@@ -118,16 +115,10 @@ describe('fake timers and missing act warnings', () => {
118115
expect(deferredStateUpdateSpy).toHaveBeenCalledTimes(1)
119116
// console.error is mocked
120117
// eslint-disable-next-line no-console
121-
expect(console.error).toHaveBeenCalledTimes(
122-
// ReactDOM.render is deprecated in React 18
123-
React.version.startsWith('18') ? 2 : 1,
124-
)
118+
expect(console.error).toHaveBeenCalledTimes(1)
125119
// 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(...)')
120+
expect(console.error.mock.calls[0][0]).toMatch(
121+
'a test was not wrapped in act(...)',
122+
)
132123
})
133124
})

src/__tests__/new-act.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let asyncAct, consoleErrorMock
1+
let asyncAct
22

33
jest.mock('react-dom/test-utils', () => ({
44
act: cb => {
@@ -8,12 +8,12 @@ jest.mock('react-dom/test-utils', () => ({
88

99
beforeEach(() => {
1010
jest.resetModules()
11-
asyncAct = require('../act-compat').asyncAct
12-
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
11+
asyncAct = require('../act-compat').default
12+
jest.spyOn(console, 'error').mockImplementation(() => {})
1313
})
1414

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

1919
test('async act works when it does not exist (older versions of react)', async () => {

src/__tests__/no-act.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)