diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 79bc62ca55..5375bba2f2 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -4977,7 +4977,7 @@ pub const ExpectMatcherContext = struct { return .zero; } const args = arguments.slice(); - return JSValue.jsBoolean(args[0].deepEquals(args[1], globalObject)); + return JSValue.jsBoolean(args[0].jestDeepEquals(args[1], globalObject)); } }; diff --git a/test/js/bun/test/expect-extend.test.js b/test/js/bun/test/expect-extend.test.js index 3f799d886e..ee707d0a78 100644 --- a/test/js/bun/test/expect-extend.test.js +++ b/test/js/bun/test/expect-extend.test.js @@ -50,6 +50,9 @@ expect.extend({ return { message, pass }; }, + _toCustomEqual(actual, expected) { + return { pass: this.equals(actual, expected) }; + }, // this matcher has not been defined through declaration merging, but expect.extends should allow it anyways, // type-enforcing the generic signature @@ -340,3 +343,14 @@ it("should propagate errors from calling .toString() on the message callback val "i have successfully propagated the error message!", ); }); + +it("should support asymmetric matchers", () => { + expect(1)._toCustomEqual(expect.anything()); + expect(1)._toCustomEqual(expect.any(Number)); + expect({ a: "test" })._toCustomEqual({ a: expect.any(String) }); + expect(() => expect(1)._toCustomEqual(expect.any(String))).toThrow(); + + expect(1).not._toCustomEqual(expect.any(String)); + expect({ a: "test" }).not._toCustomEqual({ a: expect.any(Number) }); + expect(() => expect(1).not._toCustomEqual(expect.any(Number))).toThrow(); +}); diff --git a/test/js/bun/test/expect-extend.types.d.ts b/test/js/bun/test/expect-extend.types.d.ts index 218521cd4b..ace5276b6c 100644 --- a/test/js/bun/test/expect-extend.types.d.ts +++ b/test/js/bun/test/expect-extend.types.d.ts @@ -8,6 +8,7 @@ interface CustomMatchersForTest { _toBeDivisibleBy(value: number): any; _toBeSymbol(value: Symbol): any; _toBeWithinRange(floor: number, ceiling: number): any; + _toCustomEqual(value: any): any; _shouldNotError(): any; _toFailWithoutMessage(): any; _toBeOne(): any;