@@ -23,9 +23,7 @@ import {noColor} from 'jest-diff';
2323import { getType , isPrimitive } from 'jest-get-type' ;
2424import {
2525 DIM_COLOR ,
26- EXPECTED_COLOR ,
2726 MatcherHintOptions ,
28- RECEIVED_COLOR ,
2927 SUGGEST_TO_CONTAIN_EQUAL ,
3028 ensureExpectedIsNonNegativeInteger ,
3129 ensureNoExpected ,
@@ -157,14 +155,12 @@ const matchers: MatchersObject = {
157155 secondArgument,
158156 secondArgumentColor : ( arg : string ) => arg ,
159157 } ;
160- const hintExpectedColor = options . expectedColor ?? EXPECTED_COLOR ;
161- const hintReceivedColor = options . receivedColor ?? RECEIVED_COLOR ;
162158
163159 if ( typeof expected !== 'number' ) {
164160 throw new Error (
165161 matcherErrorMessage (
166162 matcherHint ( matcherName , undefined , undefined , options ) ,
167- `${ hintExpectedColor ( 'expected' ) } value must be a number` ,
163+ `${ this . utils . hintExpectedColor ( 'expected' ) } value must be a number` ,
168164 printWithType ( 'Expected' , expected , printExpected ) ,
169165 ) ,
170166 ) ;
@@ -174,7 +170,7 @@ const matchers: MatchersObject = {
174170 throw new Error (
175171 matcherErrorMessage (
176172 matcherHint ( matcherName , undefined , undefined , options ) ,
177- `${ hintReceivedColor ( 'received' ) } value must be a number` ,
173+ `${ this . utils . hintReceivedColor ( 'received' ) } value must be a number` ,
178174 printWithType ( 'Received' , received , printReceived ) ,
179175 ) ,
180176 ) ;
@@ -326,13 +322,13 @@ const matchers: MatchersObject = {
326322 promise : this . promise ,
327323 } ;
328324
329- const hintExpectedColor = options . expectedColor ?? EXPECTED_COLOR ;
330-
331325 if ( typeof expected !== 'function' ) {
332326 throw new Error (
333327 matcherErrorMessage (
334328 matcherHint ( matcherName , undefined , undefined , options ) ,
335- `${ hintExpectedColor ( 'expected' ) } value must be a function` ,
329+ `${ this . utils . hintExpectedColor (
330+ 'expected' ,
331+ ) } value must be a function`,
336332 printWithType ( 'Expected' , expected , printExpected ) ,
337333 ) ,
338334 ) ;
@@ -523,14 +519,11 @@ const matchers: MatchersObject = {
523519 promise : this . promise ,
524520 } ;
525521
526- const hintReceivedColor = options . receivedColor ?? RECEIVED_COLOR ;
527- const hintExpectedColor = options . expectedColor ?? EXPECTED_COLOR ;
528-
529522 if ( received == null ) {
530523 throw new Error (
531524 matcherErrorMessage (
532525 matcherHint ( matcherName , undefined , undefined , options ) ,
533- `${ hintReceivedColor (
526+ `${ this . utils . hintReceivedColor (
534527 'received' ,
535528 ) } value must not be null nor undefined`,
536529 printWithType ( 'Received' , received , printReceived ) ,
@@ -539,9 +532,9 @@ const matchers: MatchersObject = {
539532 }
540533
541534 if ( typeof received === 'string' ) {
542- const wrongTypeErrorMessage = `${ hintExpectedColor (
535+ const wrongTypeErrorMessage = `${ this . utils . hintExpectedColor (
543536 'expected' ,
544- ) } value must be a string if ${ hintReceivedColor (
537+ ) } value must be a string if ${ this . utils . hintReceivedColor (
545538 'received' ,
546539 ) } value is a string`;
547540
@@ -635,13 +628,11 @@ const matchers: MatchersObject = {
635628 promise : this . promise ,
636629 } ;
637630
638- const hintReceivedColor = options . receivedColor ?? RECEIVED_COLOR ;
639-
640631 if ( received == null ) {
641632 throw new Error (
642633 matcherErrorMessage (
643634 matcherHint ( matcherName , undefined , undefined , options ) ,
644- `${ hintReceivedColor (
635+ `${ this . utils . hintReceivedColor (
645636 'received' ,
646637 ) } value must not be null nor undefined`,
647638 printWithType ( 'Received' , received , printReceived ) ,
@@ -735,13 +726,11 @@ const matchers: MatchersObject = {
735726 promise : this . promise ,
736727 } ;
737728
738- const hintReceivedColor = options . receivedColor ?? RECEIVED_COLOR ;
739-
740729 if ( typeof received ?. length !== 'number' ) {
741730 throw new Error (
742731 matcherErrorMessage (
743732 matcherHint ( matcherName , undefined , undefined , options ) ,
744- `${ hintReceivedColor (
733+ `${ this . utils . hintReceivedColor (
745734 'received' ,
746735 ) } value must have a length property whose value must be a number`,
747736 printWithType ( 'Received' , received , printReceived ) ,
@@ -802,14 +791,11 @@ const matchers: MatchersObject = {
802791 secondArgument : hasValue ? 'value' : '' ,
803792 } ;
804793
805- const hintExpectedColor = options . expectedColor ?? EXPECTED_COLOR ;
806- const hintReceivedColor = options . receivedColor ?? RECEIVED_COLOR ;
807-
808794 if ( received === null || received === undefined ) {
809795 throw new Error (
810796 matcherErrorMessage (
811797 matcherHint ( matcherName , undefined , expectedArgument , options ) ,
812- `${ hintReceivedColor (
798+ `${ this . utils . hintReceivedColor (
813799 'received' ,
814800 ) } value must not be null nor undefined`,
815801 printWithType ( 'Received' , received , printReceived ) ,
@@ -823,7 +809,9 @@ const matchers: MatchersObject = {
823809 throw new Error (
824810 matcherErrorMessage (
825811 matcherHint ( matcherName , undefined , expectedArgument , options ) ,
826- `${ hintExpectedColor ( 'expected' ) } path must be a string or array` ,
812+ `${ this . utils . hintExpectedColor (
813+ 'expected' ,
814+ ) } path must be a string or array`,
827815 printWithType ( 'Expected' , expectedPath , printExpected ) ,
828816 ) ,
829817 ) ;
@@ -838,7 +826,9 @@ const matchers: MatchersObject = {
838826 throw new Error (
839827 matcherErrorMessage (
840828 matcherHint ( matcherName , undefined , expectedArgument , options ) ,
841- `${ hintExpectedColor ( 'expected' ) } path must not be an empty array` ,
829+ `${ this . utils . hintExpectedColor (
830+ 'expected' ,
831+ ) } path must not be an empty array`,
842832 printWithType ( 'Expected' , expectedPath , printExpected ) ,
843833 ) ,
844834 ) ;
@@ -929,14 +919,11 @@ const matchers: MatchersObject = {
929919 promise : this . promise ,
930920 } ;
931921
932- const hintExpectedColor = options . receivedColor ?? EXPECTED_COLOR ;
933- const hintReceivedColor = options . receivedColor ?? RECEIVED_COLOR ;
934-
935922 if ( typeof received !== 'string' ) {
936923 throw new Error (
937924 matcherErrorMessage (
938925 matcherHint ( matcherName , undefined , undefined , options ) ,
939- `${ hintReceivedColor ( 'received' ) } value must be a string` ,
926+ `${ this . utils . hintReceivedColor ( 'received' ) } value must be a string` ,
940927 printWithType ( 'Received' , received , printReceived ) ,
941928 ) ,
942929 ) ;
@@ -949,7 +936,7 @@ const matchers: MatchersObject = {
949936 throw new Error (
950937 matcherErrorMessage (
951938 matcherHint ( matcherName , undefined , undefined , options ) ,
952- `${ hintExpectedColor (
939+ `${ this . utils . hintExpectedColor (
953940 'expected' ,
954941 ) } value must be a string or regular expression`,
955942 printWithType ( 'Expected' , expected , printExpected ) ,
@@ -1023,14 +1010,13 @@ const matchers: MatchersObject = {
10231010 promise : this . promise ,
10241011 } ;
10251012
1026- const hintReceivedColor = options . receivedColor ?? RECEIVED_COLOR ;
1027- const hintExpectedColor = options . receivedColor ?? EXPECTED_COLOR ;
1028-
10291013 if ( typeof received !== 'object' || received === null ) {
10301014 throw new Error (
10311015 matcherErrorMessage (
10321016 matcherHint ( matcherName , undefined , undefined , options ) ,
1033- `${ hintReceivedColor ( 'received' ) } value must be a non-null object` ,
1017+ `${ this . utils . hintReceivedColor (
1018+ 'received' ,
1019+ ) } value must be a non-null object`,
10341020 printWithType ( 'Received' , received , printReceived ) ,
10351021 ) ,
10361022 ) ;
@@ -1040,7 +1026,9 @@ const matchers: MatchersObject = {
10401026 throw new Error (
10411027 matcherErrorMessage (
10421028 matcherHint ( matcherName , undefined , undefined , options ) ,
1043- `${ hintExpectedColor ( 'expected' ) } value must be a non-null object` ,
1029+ `${ this . utils . hintExpectedColor (
1030+ 'expected' ,
1031+ ) } value must be a non-null object`,
10441032 printWithType ( 'Expected' , expected , printExpected ) ,
10451033 ) ,
10461034 ) ;
0 commit comments