MCPcopy Create free account
hub / github.com/testing-library/user-event / matchError

Function matchError

testenv/modules/inlineSnapshot.js:55–90  ·  view source on GitHub ↗
(didThrow, actual, expected)

Source from the content-addressed store, hash-verified

53}
54
55function matchError(didThrow, actual, expected) {
56 const normalizedActual =
57 didThrow &&
58 stripAddedLinebreaks(
59 stripAddedIndentation(
60 typeof actual === 'object' && 'message' in actual
61 ? actual.message
62 : String(actual),
63 ),
64 )
65 const normalizedExpected = stripAddedLinebreaks(
66 stripAddedIndentation(expected),
67 )
68
69 return {
70 pass: this.isNot === !didThrow && normalizedActual === normalizedExpected,
71 message: () =>
72 [
73 this.utils.matcherHint(
74 'toThrowErrorMatchingInlineSnapshot',
75 undefined,
76 undefined,
77 {
78 isNot: this.isNot,
79 promise: this.promise,
80 },
81 ),
82 '',
83 didThrow
84 ? this.utils.diff(normalizedExpected, normalizedActual, {
85 expand: this.expand,
86 })
87 : '[Did not throw]',
88 ].join('\n'),
89 }
90}
91
92function stripAddedLinebreaks(normalizedSnapshot) {
93 return normalizedSnapshot.startsWith('\n') &&

Callers

nothing calls this directly

Calls 2

stripAddedLinebreaksFunction · 0.85
stripAddedIndentationFunction · 0.85

Tested by

no test coverage detected