Skip to content

Commit 82ee012

Browse files
committed
use modern React.act
1 parent da1eefa commit 82ee012

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/pure.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22
import ReactDOM from 'react-dom'
3-
import {act as domAct} from 'react-dom/test-utils'
3+
import * as DeprecatedReactTestUtils from 'react-dom/test-utils'
44
import * as ReactDOMClient from 'react-dom/client'
55
import {
66
getQueriesForElement,
@@ -323,25 +323,20 @@ async function renderHook(renderCallback, options = {}) {
323323
return {result, rerender, unmount}
324324
}
325325

326-
function compatAct(scope) {
327-
// scope passed to domAct needs to be `async` until React.act treats every scope as async.
326+
const reactAct =
327+
typeof React.act === 'function' ? React.act : DeprecatedReactTestUtils.act
328+
329+
function act(scope) {
330+
// scope passed to reactAct needs to be `async` until React.act treats every scope as async.
328331
// We already enforce `await act()` (regardless of scope) to flush microtasks
329332
// inside the act scope.
330-
return domAct(async () => {
333+
return reactAct(async () => {
331334
return scope()
332335
})
333336
}
334337

335338
// just re-export everything from dom-testing-library
336339
export * from '@testing-library/dom'
337-
export {
338-
render,
339-
renderHook,
340-
cleanup,
341-
compatAct as act,
342-
fireEvent,
343-
getConfig,
344-
configure,
345-
}
340+
export {render, renderHook, cleanup, act, fireEvent, getConfig, configure}
346341

347342
/* eslint func-name-matching:0 */

0 commit comments

Comments
 (0)