test: Add flushPromises utility function

This commit is contained in:
Joachim Van Herwegen
2022-03-31 12:07:02 +02:00
parent 76548011f2
commit 16e9368734
7 changed files with 40 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ import { AppRunner } from '../../../src/init/AppRunner';
import type { CliExtractor } from '../../../src/init/cli/CliExtractor';
import type { SettingsResolver } from '../../../src/init/variables/SettingsResolver';
import { joinFilePath } from '../../../src/util/PathUtil';
import { flushPromises } from '../../util/Util';
const app: jest.Mocked<App> = {
start: jest.fn(),
@@ -315,9 +316,7 @@ describe('AppRunner', (): void => {
new AppRunner().runCliSync({ argv: [ 'node', 'script' ]});
// Wait until app.start has been called, because we can't await AppRunner.run.
await new Promise((resolve): void => {
setImmediate(resolve);
});
await flushPromises();
expect(ComponentsManager.build).toHaveBeenCalledTimes(1);
expect(ComponentsManager.build).toHaveBeenCalledWith({
@@ -348,9 +347,7 @@ describe('AppRunner', (): void => {
new AppRunner().runCliSync({ argv: [ 'node', 'script' ]});
// Wait until app.start has been called, because we can't await AppRunner.runCli.
await new Promise((resolve): void => {
setImmediate(resolve);
});
await flushPromises();
expect(write).toHaveBeenCalledTimes(1);
expect(write).toHaveBeenLastCalledWith(expect.stringMatching(/Cause: Fatal/mu));