Skip to content

Commit

Permalink
use wrapContextName later to grep proper error when snapshots not sup…
Browse files Browse the repository at this point in the history
…ported
  • Loading branch information
ChALkeR committed Jul 13, 2024
1 parent d6086e1 commit c331e0a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/jest.snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,21 @@ const snapInline = (obj, inline) => {
getAssert().strictEqual(serialize(obj).trim(), inline.trim())
}

const snapOnDisk = (obj) =>
wrapContextName(() => {
maybeSetupJestSnapshots()
const snapOnDisk = (obj) => {
maybeSetupJestSnapshots()

if (!serialize(obj).includes('\n')) {
// Node.js always wraps with newlines, while jest wraps only those that are already multiline
try {
getAssert().snapshot(obj)
} catch (e) {
if (`\n${e.expected}\n` === e.actual) return
throw e
}
if (!serialize(obj).includes('\n')) {
// Node.js always wraps with newlines, while jest wraps only those that are already multiline
try {
wrapContextName(() => getAssert().snapshot(obj))
} catch (e) {
if (`\n${e.expected}\n` === e.actual) return
throw e
}
}

return getAssert().snapshot(obj)
})
return wrapContextName(() => getAssert().snapshot(obj))
}

expect.extend({
toMatchInlineSnapshot: (obj, i) => wrap(() => snapInline(obj, i)),
Expand Down

0 comments on commit c331e0a

Please sign in to comment.