Skip to content

Commit 5f73381

Browse files
committed
just portals
1 parent 2b3d71e commit 5f73381

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/__tests__/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ test.each([
295295
// There are two possible scenarios:
296296
// 1. If that effect is flushed during the click the native click listener would still receive the event that caused the native listener to be added.
297297
// 2. If that effect is flushed before we return from fireEvent.click the native click listener would not receive the event that caused the native listener to be added.
298-
// React flushes effects scheduled from an update by a "discrete" event immediately.
298+
// React flushes effects scheduled from an update by a "discrete" event immediately if that effect was scheduled from a portaled component.
299299
// but not effects in a batched context (e.g. act(() => {}))
300300
// So if we were in act(() => {}), we would see scenario 2 i.e. `onDocumentClick` would not be called
301301
// If we were not in `act(() => {})`, we would see scenario 1 i.e. `onDocumentClick` would already be called

src/fire-event.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ function isDiscreteEvent(type) {
5959
}
6060

6161
function noAct(cb) {
62+
// Don't alter semantics of `cb`.
6263
cb()
64+
// But make sure updates are flushed before returning.
65+
act(() => {})
6366
}
6467

6568
// react-testing-library's version of fireEvent will call

0 commit comments

Comments
 (0)