diff --git a/packages/expect/src/jest-expect.ts b/packages/expect/src/jest-expect.ts index f3de46d13cab..d880c52501e9 100644 --- a/packages/expect/src/jest-expect.ts +++ b/packages/expect/src/jest-expect.ts @@ -376,13 +376,34 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { ) }) def('toBeNaN', function () { - return this.be.NaN + const obj = utils.flag(this, 'object') + this.assert( + Number.isNaN(obj), + 'expected #{this} to be NaN', + 'expected #{this} not to be NaN', + NaN, + obj, + ) }) def('toBeUndefined', function () { - return this.be.undefined + const obj = utils.flag(this, 'object') + this.assert( + undefined === obj, + 'expected #{this} to be undefined', + 'expected #{this} not to be undefined', + undefined, + obj, + ) }) def('toBeNull', function () { - return this.be.null + const obj = utils.flag(this, 'object') + this.assert( + null === obj, + 'expected #{this} to be null', + 'expected #{this} not to be null', + null, + obj, + ) }) def('toBeDefined', function () { const obj = utils.flag(this, 'object') diff --git a/test/core/test/__snapshots__/jest-expect.test.ts.snap b/test/core/test/__snapshots__/jest-expect.test.ts.snap index 035c52bb4b03..ced7d75d7410 100644 --- a/test/core/test/__snapshots__/jest-expect.test.ts.snap +++ b/test/core/test/__snapshots__/jest-expect.test.ts.snap @@ -327,17 +327,68 @@ undefined", exports[`diff 2`] = ` { "actual": "Object { - "k": "v", + "hello": "world", }", "diff": "- Expected: false + Received: Object { - "k": "v", + "hello": "world", }", "expected": "false", - "message": "expected { k: 'v' } to be falsy", + "message": "expected { hello: 'world' } to be falsy", +} +`; + +exports[`diff 3`] = ` +{ + "actual": "Object { + "hello": "world", +}", + "diff": "- Expected: +NaN + ++ Received: +Object { + "hello": "world", +}", + "expected": "NaN", + "message": "expected { hello: 'world' } to be NaN", +} +`; + +exports[`diff 4`] = ` +{ + "actual": "Object { + "hello": "world", +}", + "diff": "- Expected: +undefined + ++ Received: +Object { + "hello": "world", +}", + "expected": "undefined", + "message": "expected { hello: 'world' } to be undefined", +} +`; + +exports[`diff 5`] = ` +{ + "actual": "Object { + "hello": "world", +}", + "diff": "- Expected: +null + ++ Received: +Object { + "hello": "world", +}", + "expected": "null", + "message": "expected { hello: 'world' } to be null", } `; diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index 52bba2e0f50f..620e0240bc02 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -1357,5 +1357,8 @@ it('timeout', () => new Promise(resolve => setTimeout(resolve, 500))) it('diff', () => { snapshotError(() => expect(undefined).toBeTruthy()) - snapshotError(() => expect({ k: 'v' }).toBeFalsy()) + snapshotError(() => expect({ hello: 'world' }).toBeFalsy()) + snapshotError(() => expect({ hello: 'world' }).toBeNaN()) + snapshotError(() => expect({ hello: 'world' }).toBeUndefined()) + snapshotError(() => expect({ hello: 'world' }).toBeNull()) })