Skip to content

Commit 1af1505

Browse files
committed
fix waitFor* in concurrent Reat
1 parent c83e9c1 commit 1af1505

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/__tests__/end-to-end.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ class ComponentWithLoader extends React.Component {
3030
}
3131

3232
test('it waits for the data to be loaded', async () => {
33-
// TODO: https://github.com/reactwg/react-18/discussions/23#discussioncomment-812450
34-
jest.useFakeTimers()
35-
3633
render(<ComponentWithLoader />)
3734
const loading = () => screen.getByText('Loading...')
3835
await waitForElementToBeRemoved(loading)

src/pure.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ import {
44
getQueriesForElement,
55
prettyDOM,
66
configure as configureDTL,
7+
waitFor as waitForDTL,
8+
waitForElementToBeRemoved as waitForElementToBeRemovedDTL,
79
} from '@testing-library/dom'
810
import act, {asyncAct} from './act-compat'
911
import {fireEvent} from './fire-event'
1012

1113
configureDTL({
12-
asyncWrapper: async cb => {
13-
let result
14-
await asyncAct(async () => {
15-
result = await cb()
16-
})
17-
return result
18-
},
1914
eventWrapper: cb => {
2015
let result
2116
act(() => {
@@ -197,9 +192,29 @@ function cleanup() {
197192
mountedContainers.clear()
198193
}
199194

195+
function waitFor(callback, options) {
196+
return waitForDTL(() => {
197+
let result
198+
act(() => {
199+
result = callback()
200+
})
201+
return result
202+
}, options)
203+
}
204+
205+
function waitForElementToBeRemoved(callback, options) {
206+
return waitForElementToBeRemovedDTL(() => {
207+
let result
208+
act(() => {
209+
result = callback()
210+
})
211+
return result
212+
}, options)
213+
}
214+
200215
// just re-export everything from dom-testing-library
201216
export * from '@testing-library/dom'
202-
export {render, cleanup, act, fireEvent}
217+
export {render, cleanup, act, fireEvent, waitFor, waitForElementToBeRemoved}
203218

204219
// NOTE: we're not going to export asyncAct because that's our own compatibility
205220
// thing for people using react-dom@16.8.0. Anyone else doesn't need it and

0 commit comments

Comments
 (0)