diff --git a/src/matchers/is-number.spec.ts b/src/matchers/is-number.spec.ts index 8bb14bb..9454985 100644 --- a/src/matchers/is-number.spec.ts +++ b/src/matchers/is-number.spec.ts @@ -48,4 +48,16 @@ describe('isNumber', () => { it('should pretty print', () => { expect(isNumber().toJSON()).toEqual('number'); }); + + it('should return diff', () => { + expect(isNumber().getDiff('NaN')).toEqual({ + expected: 'number', + actual: '"NaN" (string)', + }); + + expect(isNumber().getDiff({ foo: 'bar' })).toEqual({ + expected: 'number', + actual: '{"foo": "bar"} (object)', + }); + }); }); diff --git a/src/matchers/is-number.ts b/src/matchers/is-number.ts index 600bfa7..4aec262 100644 --- a/src/matchers/is-number.ts +++ b/src/matchers/is-number.ts @@ -1,3 +1,5 @@ +import stripAnsi from 'strip-ansi'; +import { printArg } from '../print'; import type { TypeMatcher } from './matcher'; import { matches } from './matcher'; @@ -14,4 +16,8 @@ import { matches } from './matcher'; export const isNumber = (): TypeMatcher => matches((actual) => typeof actual === 'number' && !Number.isNaN(actual), { toJSON: () => 'number', + getDiff: (actual) => ({ + actual: `${stripAnsi(printArg(actual, true))} (${typeof actual})`, + expected: 'number', + }), });