fix: make expect(..., message) consistent as error message prefix (… · vitest-dev/vitest@a1b5f0f (original) (raw)
`@@ -89,7 +89,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
`
89
89
`received: utils.flag(this, 'object'),
`
90
90
` ...normalizeArguments(propertiesOrHint, hint),
`
91
91
`})
`
92
``
`-
return assertMatchResult(result)
`
``
92
`+
return assertMatchResult(result, chai.util.flag(this, 'message'))
`
93
93
`}),
`
94
94
`)
`
95
95
`}
`
`@@ -108,7 +108,9 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
`
108
108
` filepath,
`
109
109
` hint,
`
110
110
`})
`
111
``
`-
const assertPromise = resultPromise.then(result => assertMatchResult(result))
`
``
111
`+
const assertPromise = resultPromise.then(result =>
`
``
112
`+
assertMatchResult(result, chai.util.flag(this, 'message')),
`
``
113
`+
)
`
112
114
`return recordAsyncExpect(
`
113
115
`getTest(this),
`
114
116
`assertPromise,
`
`@@ -134,7 +136,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
`
134
136
`isInline: true,
`
135
137
` ...normalizeInlineArguments(propertiesOrInlineSnapshot, inlineSnapshotOrHint, hint),
`
136
138
`})
`
137
``
`-
return assertMatchResult(result)
`
``
139
`+
return assertMatchResult(result, chai.util.flag(this, 'message'))
`
138
140
`}),
`
139
141
`)
`
140
142
`utils.addMethod(
`
`@@ -149,7 +151,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
`
149
151
`received: getError(received, promise),
`
150
152
` ...normalizeArguments(propertiesOrHint, hint),
`
151
153
`})
`
152
``
`-
return assertMatchResult(result)
`
``
154
`+
return assertMatchResult(result, chai.util.flag(this, 'message'))
`
153
155
`}),
`
154
156
`)
`
155
157
`utils.addMethod(
`
`@@ -169,7 +171,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
`
169
171
`isInline: true,
`
170
172
` ...normalizeInlineArguments(undefined, inlineSnapshotOrHint, hint),
`
171
173
`})
`
172
``
`-
return assertMatchResult(result)
`
``
174
`+
return assertMatchResult(result, chai.util.flag(this, 'message'))
`
173
175
`}),
`
174
176
`)
`
175
177
`utils.addMethod(chai.expect, 'addSnapshotSerializer', addSerializer)
`
`@@ -221,7 +223,6 @@ function toMatchSnapshotImpl(options: {
`
221
223
`message: options.hint,
`
222
224
`isInline: options.isInline,
`
223
225
`inlineSnapshot: options.inlineSnapshot,
`
224
``
`-
errorMessage: chai.util.flag(assertion, 'message'),
`
225
226
`` // pass assertionName for inline snapshot stack probing
``
226
227
` assertionName,
`
227
228
`// set by async assertion (e.g. resolves/rejects) for inline snapshot stack probing
`
`@@ -246,7 +247,6 @@ async function toMatchFileSnapshotImpl(options: {
`
246
247
`return getSnapshotClient().match({
`
247
248
`received: options.received,
`
248
249
`message: options.hint,
`
249
``
`-
errorMessage: chai.util.flag(assertion, 'message'),
`
250
250
`rawSnapshot: {
`
251
251
`file: rawSnapshotFile,
`
252
252
`content: rawSnapshotContent ?? undefined,
`
`@@ -255,9 +255,10 @@ async function toMatchFileSnapshotImpl(options: {
`
255
255
`})
`
256
256
`}
`
257
257
``
258
``
`-
function assertMatchResult(result: SyncExpectationResult): void {
`
``
258
`+
function assertMatchResult(result: SyncExpectationResult, customMessage?: string): void {
`
259
259
`if (!result.pass) {
`
260
``
`-
throw Object.assign(new Error(result.message()), {
`
``
260
`` +
const errorMessage = (customMessage ? ${customMessage}: : '') + result.message()
``
``
261
`+
throw Object.assign(new Error(errorMessage), {
`
261
262
`actual: result.actual,
`
262
263
`expected: result.expected,
`
263
264
`diffOptions: {
`