-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
act: Add test for bypassing queueMicrotask (#21743)
Test for fix added in #21740
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/react-reconciler/src/__tests__/ReactIsomorphicAct-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @jest-environment node | ||
*/ | ||
|
||
// sanity tests for act() | ||
|
||
let React; | ||
let ReactNoop; | ||
let act; | ||
let DiscreteEventPriority; | ||
|
||
describe('isomorphic act()', () => { | ||
beforeEach(() => { | ||
React = require('react'); | ||
ReactNoop = require('react-noop-renderer'); | ||
DiscreteEventPriority = require('react-reconciler/constants') | ||
.DiscreteEventPriority; | ||
act = React.unstable_act; | ||
}); | ||
|
||
// @gate __DEV__ | ||
test('bypasses queueMicrotask', async () => { | ||
const root = ReactNoop.createRoot(); | ||
|
||
// First test what happens without wrapping in act. This update would | ||
// normally be queued in a microtask. | ||
ReactNoop.unstable_runWithPriority(DiscreteEventPriority, () => { | ||
root.render('A'); | ||
}); | ||
// Nothing has rendered yet | ||
expect(root).toMatchRenderedOutput(null); | ||
// Flush the microtasks by awaiting | ||
await null; | ||
expect(root).toMatchRenderedOutput('A'); | ||
|
||
// Now do the same thing but wrap the update with `act`. No | ||
// `await` necessary. | ||
act(() => { | ||
ReactNoop.unstable_runWithPriority(DiscreteEventPriority, () => { | ||
root.render('B'); | ||
}); | ||
}); | ||
expect(root).toMatchRenderedOutput('B'); | ||
}); | ||
}); |