Skip to content

Commit b0fd654

Browse files
committed
Merge branch 'alpha' into feat/concurrent-render
2 parents e9f188c + 84851dc commit b0fd654

File tree

6 files changed

+78
-19
lines changed

6 files changed

+78
-19
lines changed

.all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,15 @@
12791279
"contributions": [
12801280
"doc"
12811281
]
1282+
},
1283+
{
1284+
"login": "ImADrafter",
1285+
"name": "Marcos Gómez",
1286+
"avatar_url": "https://avatars.githubusercontent.com/u/44379989?v=4",
1287+
"profile": "https://github.com/ImADrafter",
1288+
"contributions": [
1289+
"doc"
1290+
]
12821291
}
12831292
],
12841293
"contributorsPerLine": 7,

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ Thanks goes to these people ([emoji key][emojis]):
611611
<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>
612612
<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>
613613
</tr>
614+
<tr>
615+
<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>
616+
</tr>
614617
</table>
615618
616619
<!-- markdownlint-restore -->

jest.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ module.exports = Object.assign(jestConfig, {
77
'./src/pure': {
88
// minimum coverage of jobs using React 17 and 18
99
branches: 80,
10-
functions: 84,
11-
lines: 89,
12-
statements: 89,
10+
functions: 78,
11+
lines: 84,
12+
statements: 84,
1313
},
1414
},
1515
})

src/__tests__/end-to-end.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,30 @@ const fetchAMessage = () =>
1111
}, randomTimeout)
1212
})
1313

14-
class ComponentWithLoader extends React.Component {
15-
state = {loading: true}
16-
async componentDidMount() {
17-
const data = await fetchAMessage()
18-
this.setState({data, loading: false}) // eslint-disable-line
19-
}
20-
render() {
21-
if (this.state.loading) {
22-
return <div>Loading...</div>
14+
function ComponentWithLoader() {
15+
const [state, setState] = React.useState({data: undefined, loading: true})
16+
React.useEffect(() => {
17+
let cancelled = false
18+
fetchAMessage().then(data => {
19+
if (!cancelled) {
20+
setState({data, loading: false})
21+
}
22+
})
23+
24+
return () => {
25+
cancelled = true
2326
}
24-
return (
25-
<div data-testid="message">
26-
Loaded this message: {this.state.data.returnedMessage}!
27-
</div>
28-
)
27+
}, [])
28+
29+
if (state.loading) {
30+
return <div>Loading...</div>
2931
}
32+
33+
return (
34+
<div data-testid="message">
35+
Loaded this message: {state.data.returnedMessage}!
36+
</div>
37+
)
3038
}
3139

3240
describe.each([

src/pure.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ import {
55
prettyDOM,
66
configure as configureDTL,
77
} from '@testing-library/dom'
8-
import act from './act-compat'
8+
import act, {asyncAct} from './act-compat'
99
import {fireEvent} from './fire-event'
1010

1111
configureDTL({
12+
asyncWrapper: async cb => {
13+
let result
14+
await asyncAct(async () => {
15+
result = await cb()
16+
})
17+
return result
18+
},
1219
eventWrapper: cb => {
1320
let result
1421
act(() => {
@@ -18,7 +25,7 @@ configureDTL({
1825
},
1926
})
2027

21-
if (typeof React.startTransition !== undefined) {
28+
if (React.startTransition !== undefined) {
2229
configureDTL({
2330
unstable_advanceTimersWrapper: cb => {
2431
return act(cb)

types/index.d.ts

+32
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,47 @@ export interface RenderOptions<
3434
Q extends Queries = typeof queries,
3535
Container extends Element | DocumentFragment = HTMLElement,
3636
> {
37+
/**
38+
* By default, React Testing Library will create a div and append that div to the document.body. Your React component will be rendered in the created div. If you provide your own HTMLElement container via this option,
39+
* it will not be appended to the document.body automatically.
40+
*
41+
* For example: If you are unit testing a `<tbody>` element, it cannot be a child of a div. In this case, you can
42+
* specify a table as the render container.
43+
*
44+
* @see https://testing-library.com/docs/react-testing-library/api/#container
45+
*/
3746
container?: Container
47+
/**
48+
* Defaults to the container if the container is specified. Otherwise `document.body` is used for the default. This is used as
49+
* the base element for the queries as well as what is printed when you use `debug()`.
50+
*
51+
* @see https://testing-library.com/docs/react-testing-library/api/#baseelement
52+
*/
3853
baseElement?: Element
54+
/**
55+
* If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
56+
* rendering and use ReactDOM.hydrate to mount your components.
57+
*
58+
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
59+
*/
3960
hydrate?: boolean
4061
/**
4162
* Set to `true` if you want to force synchronous `ReactDOM.render`.
4263
* Otherwise `render` will default to concurrent React if available.
4364
*/
4465
legacyRoot?: boolean
66+
/**
67+
* Queries to bind. Overrides the default set from DOM Testing Library unless merged.
68+
*
69+
* @see https://testing-library.com/docs/react-testing-library/api/#queries
70+
*/
4571
queries?: Q
72+
/**
73+
* Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
74+
* reusable custom render functions for common data providers. See setup for examples.
75+
*
76+
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
77+
*/
4678
wrapper?: React.ComponentType
4779
}
4880

0 commit comments

Comments
 (0)