Skip to content

Commit

Permalink
chore: keep expected and actual on the error
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 20, 2023
1 parent 07aafa7 commit 14c5b1d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 62 deletions.
7 changes: 6 additions & 1 deletion packages/runner/src/utils/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepClone, format, getOwnProperties, getType } from '@vitest/utils'
import { deepClone, format, getOwnProperties, getType, stringify } from '@vitest/utils'
import type { DiffOptions } from '@vitest/utils/diff'
import { unifiedDiff } from '@vitest/utils/diff'

Expand Down Expand Up @@ -123,6 +123,11 @@ export function processError(err: any, options: DiffOptions = {}) {
if (err.showDiff || (err.showDiff === undefined && err.expected !== undefined && err.actual !== undefined))
err.diff = unifiedDiff(replacedActual, replacedExpected, options)

if (typeof err.expected !== 'string')
err.expected = stringify(err.expected, 10)
if (typeof err.actual !== 'string')
err.actual = stringify(err.actual, 10)

// some Error implementations don't allow rewriting message
try {
if (typeof err.message === 'string')
Expand Down
Loading

0 comments on commit 14c5b1d

Please sign in to comment.