Specifically An update to * inside a test was not wrapped in act(...) is not logged when a prior update threw.
failing test (#21766)
// @gate __DEV__
it('warns if a setState is called outside of act(...) after a component threw', () => {
let setValue = null;
function App({defaultValue}) {
if (defaultValue === undefined) {
throw new Error();
}
const [value, _setValue] = React.useState(defaultValue);
setValue = _setValue;
return value;
}
expect(() => {
act(() => {
render(<App defaultValue={undefined} />, container);
});
}).toThrow();
act(() => {
rerender(<App defaultValue={0} />, container);
});
expect(() => setValue(1)).toErrorDev([
'An update to App inside a test was not wrapped in act(...).',
]);
});
What I noticed is that in
|
if ( |
|
warnsIfNotActing === true && |
|
executionContext === NoContext && |
|
ReactCurrentActQueue.current === null && |
|
// Our internal tests use a custom implementation of `act` that works by |
|
// mocking the Scheduler package. Disable the `act` warning. |
|
// TODO: Maybe the warning should be disabled by default, and then turned |
|
// on at the testing frameworks layer? Instead of what we do now, which |
|
// is check if a `jest` global is defined. |
|
ReactCurrentActQueue.disableActWarning === false |
|
) { |
the
executionContext will still equal
RetryAfterError when we would expect a "missing act" warning.
"missing act" warnings are working as expected with legacy roots.
Specifically
An update to * inside a test was not wrapped in act(...)is not logged when a prior update threw.failing test (#21766)
What I noticed is that in
react/packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Lines 2855 to 2865 in 27c9c95
the
executionContextwill still equalRetryAfterErrorwhen we would expect a "missing act" warning."missing act" warnings are working as expected with legacy roots.