Skip to content

Commit

Permalink
chore: fix windows test
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Sep 18, 2023
1 parent e943196 commit b38ee76
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-sparse-arrays */
import { AssertionError } from 'node:assert'
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import { describe, expect, it, vi } from 'vitest'
import { generateToBeMessage, setupColors } from '@vitest/expect'
import { processError } from '@vitest/utils/error'
import { getDefaultColors } from '@vitest/utils'
import { resolve } from 'pathe'

class TestError extends Error {}

Expand Down Expand Up @@ -752,14 +752,16 @@ describe('async expect', () => {

it('printing error message', async () => {
const root = resolve(fileURLToPath(import.meta.url), '../../../../')
// have "\" on windows, and "/" on unix
const filename = fileURLToPath(import.meta.url).replace(root, '<root>')
try {
await expect(Promise.resolve({ foo: { bar: 42 } })).rejects.toThrow()
expect.unreachable()
}
catch (err: any) {
const stack = err.stack.replace(new RegExp(root, 'g'), '<root>')
expect(err.message).toMatchInlineSnapshot('"promise resolved \\"{ foo: { bar: 42 } }\\" instead of rejecting"')
expect(stack).toContain('at <root>/test/core/test/jest-expect.test.ts')
expect(stack).toContain(`at ${filename}`)
}

try {
Expand All @@ -771,7 +773,7 @@ describe('async expect', () => {
catch (err: any) {
const stack = err.stack.replace(new RegExp(root, 'g'), '<root>')
expect(err.message).toMatchInlineSnapshot('"promise rejected \\"Error: some error { foo: { bar: 42 } }\\" instead of resolving"')
expect(stack).toContain('at <root>/test/core/test/jest-expect.test.ts')
expect(stack).toContain(`at ${filename}`)
}
})

Expand Down

0 comments on commit b38ee76

Please sign in to comment.