Skip to content

Commit

Permalink
Update tests to now that createRoot API is not strict by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed May 3, 2021
1 parent 0809eef commit 9091fc5
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 310 deletions.
14 changes: 4 additions & 10 deletions packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,10 @@ describe('ReactTestUtils.act()', () => {
});

// @gate experimental
it('warns in concurrent mode', () => {
expect(() => {
const root = ReactDOM.unstable_createRoot(
document.createElement('div'),
);
root.render(<App />);
Scheduler.unstable_flushAll();
}).toErrorDev([
'An update to App ran an effect, but was not wrapped in act(...)',
]);
it('does not warn in concurrent mode', () => {
const root = ReactDOM.unstable_createRoot(document.createElement('div'));
root.render(<App />);
Scheduler.unstable_flushAll();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ describe('DebugTracing', () => {
expect(logs).toEqual([
`group: ⚛️ render (${DEFAULT_LANE_STRING})`,
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`,
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`,
`groupEnd: ⚛️ render (${DEFAULT_LANE_STRING})`,
]);
});
Expand Down Expand Up @@ -366,7 +365,6 @@ describe('DebugTracing', () => {
expect(logs).toEqual([
`group: ⚛️ render (${DEFAULT_LANE_STRING})`,
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`,
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`, // debugRenderPhaseSideEffectsForStrictMode
`groupEnd: ⚛️ render (${DEFAULT_LANE_STRING})`,
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,7 @@ describe('ReactHooksWithNoopRenderer', () => {
</>,
);
expect(() =>
expect(Scheduler).toFlushAndYield(
__DEV__
? ['Foo [0]', 'Bar', 'Foo [2]']
: ['Foo [0]', 'Bar', 'Foo [1]'],
),
expect(Scheduler).toFlushAndYield(['Foo [0]', 'Bar', 'Foo [1]']),
).toErrorDev([
'Cannot update a component (`Foo`) while rendering a ' +
'different component (`Bar`). To locate the bad setState() call inside `Bar`',
Expand All @@ -536,11 +532,7 @@ describe('ReactHooksWithNoopRenderer', () => {
<Bar triggerUpdate={true} />
</>,
);
expect(Scheduler).toFlushAndYield(
__DEV__
? ['Foo [2]', 'Bar', 'Foo [4]']
: ['Foo [1]', 'Bar', 'Foo [2]'],
);
expect(Scheduler).toFlushAndYield(['Foo [1]', 'Bar', 'Foo [2]']);
});
});

Expand Down Expand Up @@ -1762,16 +1754,11 @@ describe('ReactHooksWithNoopRenderer', () => {
return <Text text={'Count: ' + count} />;
}

// we explicitly wait for missing act() warnings here since
// it's a lot harder to simulate this condition inside an act scope
expect(() => {
ReactNoop.render(<Counter count={0} />, () =>
Scheduler.unstable_yieldValue('Sync effect'),
);
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
}).toErrorDev(['An update to Counter ran an effect']);

ReactNoop.render(<Counter count={0} />, () =>
Scheduler.unstable_yieldValue('Sync effect'),
);
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
// A flush sync doesn't cause the passive effects to fire.
// So we haven't added the other update yet.
act(() => {
Expand Down
Loading

0 comments on commit 9091fc5

Please sign in to comment.