-
Notifications
You must be signed in to change notification settings - Fork 49k
expose TestUtils.act()
for batching actions in tests
#14744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e1f7952
5407e88
e8a03d0
723f347
ac7416d
1993be9
3c18517
b98d051
324fe0e
e7ebd84
0d3b45a
20a959d
ee4ebb9
4cb92ad
aa1d531
00d0614
1b2e657
86a443e
cec1ed1
a216c15
6fa4202
6cba8f5
f946089
8617b64
3bfa963
8f30593
c126f10
790ce2a
32c7e1a
5873317
0a4b3cf
b6689e1
26a6db5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import { | |
getPublicRootInstance, | ||
findHostInstance, | ||
findHostInstanceWithWarning, | ||
flushPassiveEffects, | ||
} from 'react-reconciler/inline.dom'; | ||
import {createPortal as createPortalImpl} from 'shared/ReactPortal'; | ||
import {canUseDOM} from 'shared/ExecutionEnvironment'; | ||
|
@@ -611,6 +612,13 @@ function createPortal( | |
return createPortalImpl(children, container, null, key); | ||
} | ||
|
||
// a helper for tests to scope their actions on the dom | ||
// batches and flushes effects and updates | ||
function batchedInteraction(callback: () => void) { | ||
batchedUpdates(callback); | ||
flushPassiveEffects(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should move to ReactTestUtils and instead using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, I felt icky doing this. will change, |
||
|
||
const ReactDOM: Object = { | ||
createPortal, | ||
|
||
|
@@ -822,6 +830,7 @@ const ReactDOM: Object = { | |
restoreStateIfNeeded, | ||
dispatchEvent, | ||
runEventsInBatch, | ||
batchedInteraction, | ||
], | ||
}, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ const [ | |
restoreStateIfNeeded, | ||
dispatchEvent, | ||
runEventsInBatch, | ||
batchedInteraction, | ||
] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events; | ||
|
||
function Event(suffix) {} | ||
|
@@ -380,6 +381,10 @@ const ReactTestUtils = { | |
|
||
Simulate: null, | ||
SimulateNative: {}, | ||
|
||
interact(callback: () => void) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop the |
||
batchedInteraction(callback); | ||
}, | ||
}; | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.