Skip to content

Commit

Permalink
[tests] Assert scheduler log empty in internalAct
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Apr 10, 2024
1 parent 2243b40 commit a2b6db0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/internal-test-utils/internalAct.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {Thenable} from 'shared/ReactTypes';
import * as Scheduler from 'scheduler/unstable_mock';

import enqueueTask from './enqueueTask';
import {diff} from 'jest-diff';

export let actingUpdatesScopeDepth: number = 0;

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

const actualYields = Scheduler.unstable_clearLog();
if (actualYields.length !== 0) {
const error = Error(
'Log of yielded values is not empty. Call assertLog first.\n\n' +
`Received:\n${diff('', actualYields.join('\n'), {
omitAnnotationLines: true,
})}`,
);
Error.captureStackTrace(error, act);
throw error;
}

// $FlowFixMe[cannot-resolve-name]: Flow doesn't know about global Jest object
if (!jest.isMockFunction(setTimeout)) {
throw Error(
Expand Down

0 comments on commit a2b6db0

Please sign in to comment.