Skip to content

Commit

Permalink
rest(logging): Uses "waitFor" for logs assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Aug 21, 2021
1 parent df3daa2 commit ee41237
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions test/rest-api/logging.test.ts
Original file line number Diff line number Diff line change
@@ -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') })
Expand All @@ -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$`,
),
),
),
]),
)
]),
)
})
})

0 comments on commit ee41237

Please sign in to comment.