From ee412373253343748dc8ff3a97b4b921eddc2517 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Sat, 21 Aug 2021 13:57:27 +0200 Subject: [PATCH] rest(logging): Uses "waitFor" for logs assertions --- test/rest-api/logging.test.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/rest-api/logging.test.ts b/test/rest-api/logging.test.ts index 93babac59..7c6702d27 100644 --- a/test/rest-api/logging.test.ts +++ b/test/rest-api/logging.test.ts @@ -1,6 +1,7 @@ import * as path from 'path' import { pageWith } from 'page-with' import { StatusCodeColor } from '../../src/utils/logging/getStatusCodeColor' +import { waitFor } from '../support/waitFor' function createRuntime() { return pageWith({ example: path.resolve(__dirname, 'basic.mocks.ts') }) @@ -10,13 +11,15 @@ test('prints a captured request info into browser console', async () => { const runtime = await createRuntime() await runtime.request('https://api.github.com/users/octocat') - expect(runtime.consoleSpy.get('raw').get('startGroupCollapsed')).toEqual( - expect.arrayContaining([ - expect.stringMatching( - new RegExp( - `^\\[MSW\\] %s %s %s \\(%c%s%c\\) \\d{2}:\\d{2}:\\d{2} GET https://api.github.com/users/octocat color:${StatusCodeColor.Success} 200 OK color:inherit$`, + await waitFor(() => { + expect(runtime.consoleSpy.get('raw').get('startGroupCollapsed')).toEqual( + expect.arrayContaining([ + expect.stringMatching( + new RegExp( + `^\\[MSW\\] %s %s %s \\(%c%s%c\\) \\d{2}:\\d{2}:\\d{2} GET https://api.github.com/users/octocat color:${StatusCodeColor.Success} 200 OK color:inherit$`, + ), ), - ), - ]), - ) + ]), + ) + }) })