File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -48,4 +48,16 @@ describe('isNumber', () => {
48
48
it ( 'should pretty print' , ( ) => {
49
49
expect ( isNumber ( ) . toJSON ( ) ) . toEqual ( 'number' ) ;
50
50
} ) ;
51
+
52
+ it ( 'should return diff' , ( ) => {
53
+ expect ( isNumber ( ) . getDiff ( 'NaN' ) ) . toEqual ( {
54
+ expected : 'number' ,
55
+ actual : '"NaN" (string)' ,
56
+ } ) ;
57
+
58
+ expect ( isNumber ( ) . getDiff ( { foo : 'bar' } ) ) . toEqual ( {
59
+ expected : 'number' ,
60
+ actual : '{"foo": "bar"} (object)' ,
61
+ } ) ;
62
+ } ) ;
51
63
} ) ;
Original file line number Diff line number Diff line change
1
+ import stripAnsi from 'strip-ansi' ;
2
+ import { printArg } from '../print' ;
1
3
import type { TypeMatcher } from './matcher' ;
2
4
import { matches } from './matcher' ;
3
5
@@ -14,4 +16,8 @@ import { matches } from './matcher';
14
16
export const isNumber = ( ) : TypeMatcher < number > =>
15
17
matches ( ( actual ) => typeof actual === 'number' && ! Number . isNaN ( actual ) , {
16
18
toJSON : ( ) => 'number' ,
19
+ getDiff : ( actual ) => ( {
20
+ actual : `${ stripAnsi ( printArg ( actual , true ) ) } (${ typeof actual } )` ,
21
+ expected : 'number' ,
22
+ } ) ,
17
23
} ) ;
You can’t perform that action at this time.
0 commit comments