Skip to content

Commit 6f0080f

Browse files
committed
[tests] Assert scheduler log empty in internalAct
1 parent a5aedd1 commit 6f0080f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/internal-test-utils/internalAct.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {Thenable} from 'shared/ReactTypes';
1919
import * as Scheduler from 'scheduler/unstable_mock';
2020

2121
import enqueueTask from './enqueueTask';
22+
import {diff} from 'jest-diff';
2223

2324
export let actingUpdatesScopeDepth: number = 0;
2425

@@ -45,6 +46,18 @@ export async function act<T>(scope: () => Thenable<T>): Thenable<T> {
4546
);
4647
}
4748

49+
const actualYields = Scheduler.unstable_clearLog();
50+
if (actualYields.length !== 0) {
51+
const error = Error(
52+
'Log of yielded values is not empty. Call assertLog first.\n\n' +
53+
`Received:\n${diff('', actualYields.join('\n'), {
54+
omitAnnotationLines: true,
55+
})}`,
56+
);
57+
Error.captureStackTrace(error, act);
58+
throw error;
59+
}
60+
4861
// $FlowFixMe[cannot-resolve-name]: Flow doesn't know about global Jest object
4962
if (!jest.isMockFunction(setTimeout)) {
5063
throw Error(

0 commit comments

Comments
 (0)