ITADN

expect(...).toMatchObject error is "AssertionError: Values are not equal." instead of

#6999Opendandv 创建于 2026-02-11
bugexpect
D
dandvcommented
**Describe the bug** When an expect(...).toMatchObject() fails, the failure message is "error: AssertionError: Values are not equal.". This is misleading because toMatchObject doesn't test for equality. **Steps to Reproduce** 1. Create **toMatchObject.ts**: ```ts import { test } from '@std/testing/bdd'; import { expect } from '@std/expect'; test('toMatchOBject should return fail message about matching, not equality', () => { expect({ position: { x: 0, y: 'string' } }).toMatchObject({ position: { x: expect.any(Number), y: expect.any(Number) } }); }); ``` 2. Run: ```bash $ deno test toMatchObject.ts running 1 test from ./toMatchObject.ts toMatchOBject should return fail message about matching, not equality ... FAILED (3ms) ERRORS toMatchOBject should return fail message about matching, not equality => ./toMatchObject.ts:4:1 error: AssertionError: Values are not equal. [Diff] Actual / Expected { position: { + x: Any { + inverse: false, + value: [Function: Number], + }, + y: Any { + inverse: false, + value: [Function: Number], + }, - x: 0, - y: "string", }, } throw new AssertionError( ^ at triggerError (https://jsr.io/@std/expect/1.0.17/_matchers.ts:591:13) at toMatchObject (https://jsr.io/@std/expect/1.0.17/_matchers.ts:600:5) at applyMatcher (https://jsr.io/@std/expect/1.0.17/expect.ts:223:13) at Proxy.<anonymous> (https://jsr.io/@std/expect/1.0.17/expect.ts:233:13) at Object.<anonymous> (file:///home/dandv/deno-bug/toMatchObject.ts:5:49) at fn (https://jsr.io/@std/testing/1.0.17/bdd.ts:598:20) FAILURES toMatchOBject should return fail message about matching, not equality => ./toMatchObject.ts:4:1 FAILED | 0 passed | 1 failed (12ms) error: Test failed ``` **Expected behavior** Jest fails with a much shorter, clearer, and accurate message, and a minimal diff: ``` FAIL tests/toMatchObject.test.ts ✕ toMatchOBject should return fail message about matching, not equality expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 Object { "position": Object { "x": Any<Number>, - "y": Any<Number>, + "y": "string", }, } ``` **Environment** - OS: Ununtu 24 - deno version: 2.6.8 - std version: 1.0.17
1 条评论