diff --git a/packages/expect/src/jest-expect.ts b/packages/expect/src/jest-expect.ts index a038ceada951..3d8a232c06ef 100644 --- a/packages/expect/src/jest-expect.ts +++ b/packages/expect/src/jest-expect.ts @@ -309,8 +309,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { Boolean(obj), 'expected #{this} to be truthy', 'expected #{this} to not be truthy', + true, obj, - false, ) }) def('toBeFalsy', function () { @@ -319,8 +319,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { !obj, 'expected #{this} to be falsy', 'expected #{this} to not be falsy', - obj, false, + obj, ) }) def('toBeGreaterThan', function (expected: number | bigint) { @@ -331,8 +331,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { actual > expected, `expected ${actual} to be greater than ${expected}`, `expected ${actual} to be not greater than ${expected}`, - actual, expected, + actual, false, ) }) @@ -344,8 +344,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { actual >= expected, `expected ${actual} to be greater than or equal to ${expected}`, `expected ${actual} to be not greater than or equal to ${expected}`, - actual, expected, + actual, false, ) }) @@ -357,8 +357,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { actual < expected, `expected ${actual} to be less than ${expected}`, `expected ${actual} to be not less than ${expected}`, - actual, expected, + actual, false, ) }) @@ -370,19 +370,40 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { actual <= expected, `expected ${actual} to be less than or equal to ${expected}`, `expected ${actual} to be not less than or equal to ${expected}`, - actual, expected, + actual, false, ) }) 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', + Number.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( + obj === null, + '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 85b30fbf13c6..ced7d75d7410 100644 --- a/test/core/test/__snapshots__/jest-expect.test.ts.snap +++ b/test/core/test/__snapshots__/jest-expect.test.ts.snap @@ -311,6 +311,87 @@ exports[`asymmetric matcher error 23`] = ` } `; +exports[`diff 1`] = ` +{ + "actual": "undefined", + "diff": "- Expected: +true + ++ Received: +undefined", + "expected": "true", + "message": "expected undefined to be truthy", +} +`; + +exports[`diff 2`] = ` +{ + "actual": "Object { + "hello": "world", +}", + "diff": "- Expected: +false + ++ Received: +Object { + "hello": "world", +}", + "expected": "false", + "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", +} +`; + exports[`toHaveBeenNthCalledWith error 1`] = ` { "actual": "Array [ diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index b97d1a7c6297..620e0240bc02 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -1354,3 +1354,11 @@ it('toMatch/toContain diff', () => { }) it('timeout', () => new Promise(resolve => setTimeout(resolve, 500))) + +it('diff', () => { + snapshotError(() => expect(undefined).toBeTruthy()) + snapshotError(() => expect({ hello: 'world' }).toBeFalsy()) + snapshotError(() => expect({ hello: 'world' }).toBeNaN()) + snapshotError(() => expect({ hello: 'world' }).toBeUndefined()) + snapshotError(() => expect({ hello: 'world' }).toBeNull()) +})