@@ -89,7 +89,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
8989 received : utils . flag ( this , 'object' ) ,
9090 ...normalizeArguments ( propertiesOrHint , hint ) ,
9191 } )
92- return assertMatchResult ( result )
92+ return assertMatchResult ( result , chai . util . flag ( this , 'message' ) )
9393 } ) ,
9494 )
9595 }
@@ -108,7 +108,9 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
108108 filepath,
109109 hint,
110110 } )
111- const assertPromise = resultPromise . then ( result => assertMatchResult ( result ) )
111+ const assertPromise = resultPromise . then ( result =>
112+ assertMatchResult ( result , chai . util . flag ( this , 'message' ) ) ,
113+ )
112114 return recordAsyncExpect (
113115 getTest ( this ) ,
114116 assertPromise ,
@@ -134,7 +136,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
134136 isInline : true ,
135137 ...normalizeInlineArguments ( propertiesOrInlineSnapshot , inlineSnapshotOrHint , hint ) ,
136138 } )
137- return assertMatchResult ( result )
139+ return assertMatchResult ( result , chai . util . flag ( this , 'message' ) )
138140 } ) ,
139141 )
140142 utils . addMethod (
@@ -149,7 +151,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
149151 received : getError ( received , promise ) ,
150152 ...normalizeArguments ( propertiesOrHint , hint ) ,
151153 } )
152- return assertMatchResult ( result )
154+ return assertMatchResult ( result , chai . util . flag ( this , 'message' ) )
153155 } ) ,
154156 )
155157 utils . addMethod (
@@ -169,7 +171,7 @@ export const SnapshotPlugin: ChaiPlugin = (chai, utils) => {
169171 isInline : true ,
170172 ...normalizeInlineArguments ( undefined , inlineSnapshotOrHint , hint ) ,
171173 } )
172- return assertMatchResult ( result )
174+ return assertMatchResult ( result , chai . util . flag ( this , 'message' ) )
173175 } ) ,
174176 )
175177 utils . addMethod ( chai . expect , 'addSnapshotSerializer' , addSerializer )
@@ -221,7 +223,6 @@ function toMatchSnapshotImpl(options: {
221223 message : options . hint ,
222224 isInline : options . isInline ,
223225 inlineSnapshot : options . inlineSnapshot ,
224- errorMessage : chai . util . flag ( assertion , 'message' ) ,
225226 // pass `assertionName` for inline snapshot stack probing
226227 assertionName,
227228 // set by async assertion (e.g. resolves/rejects) for inline snapshot stack probing
@@ -246,7 +247,6 @@ async function toMatchFileSnapshotImpl(options: {
246247 return getSnapshotClient ( ) . match ( {
247248 received : options . received ,
248249 message : options . hint ,
249- errorMessage : chai . util . flag ( assertion , 'message' ) ,
250250 rawSnapshot : {
251251 file : rawSnapshotFile ,
252252 content : rawSnapshotContent ?? undefined ,
@@ -255,9 +255,10 @@ async function toMatchFileSnapshotImpl(options: {
255255 } )
256256}
257257
258- function assertMatchResult ( result : SyncExpectationResult ) : void {
258+ function assertMatchResult ( result : SyncExpectationResult , customMessage ?: string ) : void {
259259 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 ) , {
261262 actual : result . actual ,
262263 expected : result . expected ,
263264 diffOptions : {
0 commit comments