@@ -230,15 +230,31 @@ export const toMatchSnapshot: MatcherFunctionWithContext<
230230export const toMatchNamedSnapshot : MatcherFunctionWithContext <
231231 Context ,
232232 [ snapshotName : string , properties ?: object ]
233- > = function ( received , snapshotName , properties ?) {
233+ > = function ( received : unknown , snapshotName : unknown , properties ?: unknown ) {
234234 const matcherName = 'toMatchNamedSnapshot' ;
235235
236+ if ( typeof snapshotName !== 'string' ) {
237+ const options : MatcherHintOptions = {
238+ isNot : this . isNot ,
239+ promise : this . promise ,
240+ } ;
241+ const printedWithType = printWithType (
242+ 'Expected snapshotName' ,
243+ snapshotName ,
244+ printExpected ,
245+ ) ;
246+
247+ throw new Error (
248+ matcherErrorMessage (
249+ matcherHint ( matcherName , undefined , PROPERTIES_ARG , options ) ,
250+ `Expected ${ EXPECTED_COLOR ( 'snapshotName' ) } must be a string` ,
251+ printedWithType ,
252+ ) ,
253+ ) ;
254+ }
255+
236256 if ( properties !== undefined ) {
237- if (
238- Array . isArray ( properties ) ||
239- typeof properties !== 'object' ||
240- properties === null
241- ) {
257+ if ( typeof properties !== 'object' || properties === null ) {
242258 const options : MatcherHintOptions = {
243259 isNot : this . isNot ,
244260 promise : this . promise ,
@@ -530,9 +546,29 @@ export const toThrowErrorMatchingInlineSnapshot: MatcherFunctionWithContext<
530546export const toThrowErrorMatchingNamedSnapshot : MatcherFunctionWithContext <
531547 Context ,
532548 [ snapshotName : string , fromPromise ?: boolean ]
533- > = function ( received , snapshotName , fromPromise ) {
549+ > = function ( received : unknown , snapshotName : unknown , fromPromise : unknown ) {
534550 const matcherName = 'toThrowErrorMatchingNamedSnapshot' ;
535551
552+ if ( typeof snapshotName !== 'string' ) {
553+ const options : MatcherHintOptions = {
554+ isNot : this . isNot ,
555+ promise : this . promise ,
556+ } ;
557+ const printedWithType = printWithType (
558+ 'Expected snapshotName' ,
559+ snapshotName ,
560+ printExpected ,
561+ ) ;
562+
563+ throw new Error (
564+ matcherErrorMessage (
565+ matcherHint ( matcherName , undefined , PROPERTIES_ARG , options ) ,
566+ `Expected ${ EXPECTED_COLOR ( 'snapshotName' ) } must be a string` ,
567+ printedWithType ,
568+ ) ,
569+ ) ;
570+ }
571+
536572 return _toThrowErrorMatchingSnapshot (
537573 {
538574 context : this ,
0 commit comments