diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 4f0a1ae4ca..c069a6d7b9 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -848,7 +848,7 @@ pub const Expect = struct { if (existing_value) |saved_value| { if (strings.eqlLong(pretty_value.slice(), saved_value, true)) { Jest.runner.?.snapshots.passed += 1; - return .js_undefined; + return this.returnMatcherValue(globalThis); } Jest.runner.?.snapshots.failed += 1; @@ -863,7 +863,7 @@ pub const Expect = struct { return globalThis.throwPretty(fmt, .{diff_format}); } - return .js_undefined; + return this.returnMatcherValue(globalThis); } pub fn getStaticNot(globalThis: *JSGlobalObject, _: JSValue, _: JSValue) bun.JSError!JSValue { @@ -1231,6 +1231,16 @@ pub const Expect = struct { vm.autoGarbageCollect(); } + /// Helper function for matchers to return the correct value based on whether + /// .resolves or .rejects was used. When async flags are set, returns a resolved promise. + /// Otherwise returns undefined. + pub inline fn returnMatcherValue(this: *const Expect, globalThis: *JSGlobalObject) JSValue { + if (this.flags.promise != .none) { + return JSPromise.resolvedPromiseValue(globalThis, .js_undefined); + } + return .js_undefined; + } + pub fn doUnreachable(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue { const arg = callframe.arguments_old(1).ptr[0]; @@ -2246,6 +2256,7 @@ const strings = bun.strings; const jsc = bun.jsc; const CallFrame = jsc.CallFrame; const JSGlobalObject = jsc.JSGlobalObject; +const JSPromise = jsc.JSPromise; const JSValue = jsc.JSValue; const VirtualMachine = jsc.VirtualMachine; const ZigString = jsc.ZigString; diff --git a/src/bun.js/test/expect/toBe.zig b/src/bun.js/test/expect/toBe.zig index 0d751eb834..5d62007475 100644 --- a/src/bun.js/test/expect/toBe.zig +++ b/src/bun.js/test/expect/toBe.zig @@ -22,7 +22,7 @@ pub fn toBe( var pass = try right.isSameValue(left, globalThis); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeArray.zig b/src/bun.js/test/expect/toBeArray.zig index d1e44968f2..62e7e6ae12 100644 --- a/src/bun.js/test/expect/toBeArray.zig +++ b/src/bun.js/test/expect/toBeArray.zig @@ -9,7 +9,7 @@ pub fn toBeArray(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra const not = this.flags.not; const pass = value.jsType().isArray() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeArrayOfSize.zig b/src/bun.js/test/expect/toBeArrayOfSize.zig index 73a6be0af1..53ba4c2161 100644 --- a/src/bun.js/test/expect/toBeArrayOfSize.zig +++ b/src/bun.js/test/expect/toBeArrayOfSize.zig @@ -24,7 +24,7 @@ pub fn toBeArrayOfSize(this: *Expect, globalThis: *JSGlobalObject, callFrame: *C var pass = value.jsType().isArray() and @as(i32, @intCast(try value.getLength(globalThis))) == size.toInt32(); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeBoolean.zig b/src/bun.js/test/expect/toBeBoolean.zig index 9593f63b12..8c828d793e 100644 --- a/src/bun.js/test/expect/toBeBoolean.zig +++ b/src/bun.js/test/expect/toBeBoolean.zig @@ -9,7 +9,7 @@ pub fn toBeBoolean(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF const not = this.flags.not; const pass = value.isBoolean() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeCloseTo.zig b/src/bun.js/test/expect/toBeCloseTo.zig index d359589612..8c44436376 100644 --- a/src/bun.js/test/expect/toBeCloseTo.zig +++ b/src/bun.js/test/expect/toBeCloseTo.zig @@ -43,7 +43,7 @@ pub fn toBeCloseTo(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF } if (std.math.isPositiveInf(expected) and std.math.isPositiveInf(received)) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } const expected_diff = bun.pow(10, -precision) / 2; @@ -53,7 +53,7 @@ pub fn toBeCloseTo(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeDate.zig b/src/bun.js/test/expect/toBeDate.zig index 3baaa2ccb7..c3f0092532 100644 --- a/src/bun.js/test/expect/toBeDate.zig +++ b/src/bun.js/test/expect/toBeDate.zig @@ -9,7 +9,7 @@ pub fn toBeDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram const not = this.flags.not; const pass = value.isDate() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeDefined.zig b/src/bun.js/test/expect/toBeDefined.zig index 85ac9ee744..86e2b167a6 100644 --- a/src/bun.js/test/expect/toBeDefined.zig +++ b/src/bun.js/test/expect/toBeDefined.zig @@ -9,7 +9,7 @@ pub fn toBeDefined(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF const not = this.flags.not; var pass = !value.isUndefined(); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeEmpty.zig b/src/bun.js/test/expect/toBeEmpty.zig index 0d070ae77b..c96fd63afa 100644 --- a/src/bun.js/test/expect/toBeEmpty.zig +++ b/src/bun.js/test/expect/toBeEmpty.zig @@ -61,7 +61,7 @@ pub fn toBeEmpty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); if (not) { const signature = comptime getSignature("toBeEmpty", "", true); diff --git a/src/bun.js/test/expect/toBeEmptyObject.zig b/src/bun.js/test/expect/toBeEmptyObject.zig index 8bb13998a4..05f9bd3470 100644 --- a/src/bun.js/test/expect/toBeEmptyObject.zig +++ b/src/bun.js/test/expect/toBeEmptyObject.zig @@ -10,7 +10,7 @@ pub fn toBeEmptyObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *C var pass = try value.isObjectEmpty(globalThis); if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeEven.zig b/src/bun.js/test/expect/toBeEven.zig index c77d9199ae..7470a8738c 100644 --- a/src/bun.js/test/expect/toBeEven.zig +++ b/src/bun.js/test/expect/toBeEven.zig @@ -34,7 +34,7 @@ pub fn toBeEven(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeFalse.zig b/src/bun.js/test/expect/toBeFalse.zig index 0b533d42dc..de21e65486 100644 --- a/src/bun.js/test/expect/toBeFalse.zig +++ b/src/bun.js/test/expect/toBeFalse.zig @@ -9,7 +9,7 @@ pub fn toBeFalse(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra const not = this.flags.not; const pass = (value.isBoolean() and !value.toBoolean()) != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeFalsy.zig b/src/bun.js/test/expect/toBeFalsy.zig index bcfd1ca7b6..9f68b5cc2c 100644 --- a/src/bun.js/test/expect/toBeFalsy.zig +++ b/src/bun.js/test/expect/toBeFalsy.zig @@ -14,7 +14,7 @@ pub fn toBeFalsy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra if (!truthy) pass = true; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeFinite.zig b/src/bun.js/test/expect/toBeFinite.zig index a89c9dae27..22c71d2b99 100644 --- a/src/bun.js/test/expect/toBeFinite.zig +++ b/src/bun.js/test/expect/toBeFinite.zig @@ -15,7 +15,7 @@ pub fn toBeFinite(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeFunction.zig b/src/bun.js/test/expect/toBeFunction.zig index 27866b90fe..77d85de317 100644 --- a/src/bun.js/test/expect/toBeFunction.zig +++ b/src/bun.js/test/expect/toBeFunction.zig @@ -9,7 +9,7 @@ pub fn toBeFunction(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call const not = this.flags.not; const pass = value.isCallable() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeGreaterThan.zig b/src/bun.js/test/expect/toBeGreaterThan.zig index 9f94d23037..87d0a9347f 100644 --- a/src/bun.js/test/expect/toBeGreaterThan.zig +++ b/src/bun.js/test/expect/toBeGreaterThan.zig @@ -38,7 +38,7 @@ pub fn toBeGreaterThan(this: *Expect, globalThis: *JSGlobalObject, callFrame: *C } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeGreaterThanOrEqual.zig b/src/bun.js/test/expect/toBeGreaterThanOrEqual.zig index 15718451b3..e0a1d116d5 100644 --- a/src/bun.js/test/expect/toBeGreaterThanOrEqual.zig +++ b/src/bun.js/test/expect/toBeGreaterThanOrEqual.zig @@ -38,7 +38,7 @@ pub fn toBeGreaterThanOrEqual(this: *Expect, globalThis: *JSGlobalObject, callFr } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeInstanceOf.zig b/src/bun.js/test/expect/toBeInstanceOf.zig index 97a1c3c7a7..862b089d9d 100644 --- a/src/bun.js/test/expect/toBeInstanceOf.zig +++ b/src/bun.js/test/expect/toBeInstanceOf.zig @@ -24,7 +24,7 @@ pub fn toBeInstanceOf(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Ca const not = this.flags.not; var pass = value.isInstanceOf(globalThis, expected_value); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure const expected_fmt = expected_value.toFmt(&formatter); diff --git a/src/bun.js/test/expect/toBeInteger.zig b/src/bun.js/test/expect/toBeInteger.zig index 148ee1848d..de115a274d 100644 --- a/src/bun.js/test/expect/toBeInteger.zig +++ b/src/bun.js/test/expect/toBeInteger.zig @@ -9,7 +9,7 @@ pub fn toBeInteger(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF const not = this.flags.not; const pass = value.isAnyInt() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeLessThan.zig b/src/bun.js/test/expect/toBeLessThan.zig index 30e024ce95..bb9a29b7b2 100644 --- a/src/bun.js/test/expect/toBeLessThan.zig +++ b/src/bun.js/test/expect/toBeLessThan.zig @@ -38,7 +38,7 @@ pub fn toBeLessThan(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeLessThanOrEqual.zig b/src/bun.js/test/expect/toBeLessThanOrEqual.zig index 34ad095f0f..4049e8961e 100644 --- a/src/bun.js/test/expect/toBeLessThanOrEqual.zig +++ b/src/bun.js/test/expect/toBeLessThanOrEqual.zig @@ -38,7 +38,7 @@ pub fn toBeLessThanOrEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeNaN.zig b/src/bun.js/test/expect/toBeNaN.zig index 8621cee689..a95f912f60 100644 --- a/src/bun.js/test/expect/toBeNaN.zig +++ b/src/bun.js/test/expect/toBeNaN.zig @@ -14,7 +14,7 @@ pub fn toBeNaN(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeNegative.zig b/src/bun.js/test/expect/toBeNegative.zig index c0c9041240..ff0fa55710 100644 --- a/src/bun.js/test/expect/toBeNegative.zig +++ b/src/bun.js/test/expect/toBeNegative.zig @@ -15,7 +15,7 @@ pub fn toBeNegative(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeNil.zig b/src/bun.js/test/expect/toBeNil.zig index b695041c2d..725affb03f 100644 --- a/src/bun.js/test/expect/toBeNil.zig +++ b/src/bun.js/test/expect/toBeNil.zig @@ -9,7 +9,7 @@ pub fn toBeNil(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame const not = this.flags.not; const pass = value.isUndefinedOrNull() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeNull.zig b/src/bun.js/test/expect/toBeNull.zig index 45a1280d35..bd85e2992a 100644 --- a/src/bun.js/test/expect/toBeNull.zig +++ b/src/bun.js/test/expect/toBeNull.zig @@ -9,7 +9,7 @@ pub fn toBeNull(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram const not = this.flags.not; var pass = value.isNull(); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeNumber.zig b/src/bun.js/test/expect/toBeNumber.zig index 0a2810ada6..32cb5046f7 100644 --- a/src/bun.js/test/expect/toBeNumber.zig +++ b/src/bun.js/test/expect/toBeNumber.zig @@ -9,7 +9,7 @@ pub fn toBeNumber(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr const not = this.flags.not; const pass = value.isNumber() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeObject.zig b/src/bun.js/test/expect/toBeObject.zig index cd8072402c..8ed99ab875 100644 --- a/src/bun.js/test/expect/toBeObject.zig +++ b/src/bun.js/test/expect/toBeObject.zig @@ -9,7 +9,7 @@ pub fn toBeObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr const not = this.flags.not; const pass = value.isObject() != not; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeOdd.zig b/src/bun.js/test/expect/toBeOdd.zig index d4d477c1a3..e381319077 100644 --- a/src/bun.js/test/expect/toBeOdd.zig +++ b/src/bun.js/test/expect/toBeOdd.zig @@ -32,7 +32,7 @@ pub fn toBeOdd(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeOneOf.zig b/src/bun.js/test/expect/toBeOneOf.zig index 5d2af7e837..43f1f42fda 100644 --- a/src/bun.js/test/expect/toBeOneOf.zig +++ b/src/bun.js/test/expect/toBeOneOf.zig @@ -61,7 +61,7 @@ pub fn toBeOneOf( } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBePositive.zig b/src/bun.js/test/expect/toBePositive.zig index 9bec22e210..106858e32a 100644 --- a/src/bun.js/test/expect/toBePositive.zig +++ b/src/bun.js/test/expect/toBePositive.zig @@ -15,7 +15,7 @@ pub fn toBePositive(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeString.zig b/src/bun.js/test/expect/toBeString.zig index 9c5ffc6f47..7265a46f6d 100644 --- a/src/bun.js/test/expect/toBeString.zig +++ b/src/bun.js/test/expect/toBeString.zig @@ -9,7 +9,7 @@ pub fn toBeString(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr const not = this.flags.not; const pass = value.isString() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeSymbol.zig b/src/bun.js/test/expect/toBeSymbol.zig index 60384fd2b2..74335aa088 100644 --- a/src/bun.js/test/expect/toBeSymbol.zig +++ b/src/bun.js/test/expect/toBeSymbol.zig @@ -9,7 +9,7 @@ pub fn toBeSymbol(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr const not = this.flags.not; const pass = value.isSymbol() != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeTrue.zig b/src/bun.js/test/expect/toBeTrue.zig index cf555cdd8b..9e49adaefe 100644 --- a/src/bun.js/test/expect/toBeTrue.zig +++ b/src/bun.js/test/expect/toBeTrue.zig @@ -9,7 +9,7 @@ pub fn toBeTrue(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram const not = this.flags.not; const pass = (value.isBoolean() and value.toBoolean()) != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeTruthy.zig b/src/bun.js/test/expect/toBeTruthy.zig index 71b3ba5a87..b7638f115f 100644 --- a/src/bun.js/test/expect/toBeTruthy.zig +++ b/src/bun.js/test/expect/toBeTruthy.zig @@ -12,7 +12,7 @@ pub fn toBeTruthy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr if (truthy) pass = true; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeTypeOf.zig b/src/bun.js/test/expect/toBeTypeOf.zig index 716ee88a1b..ac7e1a1d29 100644 --- a/src/bun.js/test/expect/toBeTypeOf.zig +++ b/src/bun.js/test/expect/toBeTypeOf.zig @@ -65,7 +65,7 @@ pub fn toBeTypeOf(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr pass = strings.eql(typeof, whatIsTheType); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeUndefined.zig b/src/bun.js/test/expect/toBeUndefined.zig index 8b6f7593d2..81785657d9 100644 --- a/src/bun.js/test/expect/toBeUndefined.zig +++ b/src/bun.js/test/expect/toBeUndefined.zig @@ -10,7 +10,7 @@ pub fn toBeUndefined(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal if (value.isUndefined()) pass = true; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toBeValidDate.zig b/src/bun.js/test/expect/toBeValidDate.zig index 642bf83aac..fc941bfa93 100644 --- a/src/bun.js/test/expect/toBeValidDate.zig +++ b/src/bun.js/test/expect/toBeValidDate.zig @@ -10,7 +10,7 @@ pub fn toBeValidDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal var pass = (value.isDate() and !std.math.isNan(value.getUnixTimestamp())); if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toBeWithin.zig b/src/bun.js/test/expect/toBeWithin.zig index d4e71241e1..176d057adb 100644 --- a/src/bun.js/test/expect/toBeWithin.zig +++ b/src/bun.js/test/expect/toBeWithin.zig @@ -36,7 +36,7 @@ pub fn toBeWithin(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toContain.zig b/src/bun.js/test/expect/toContain.zig index c5fbaf3ea9..8c1f1bec62 100644 --- a/src/bun.js/test/expect/toContain.zig +++ b/src/bun.js/test/expect/toContain.zig @@ -73,7 +73,7 @@ pub fn toContain( } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainAllKeys.zig b/src/bun.js/test/expect/toContainAllKeys.zig index c06575b0cd..6d493232ba 100644 --- a/src/bun.js/test/expect/toContainAllKeys.zig +++ b/src/bun.js/test/expect/toContainAllKeys.zig @@ -43,7 +43,7 @@ pub fn toContainAllKeys( } if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalObject); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainAllValues.zig b/src/bun.js/test/expect/toContainAllValues.zig index d354157f94..525c4c3240 100644 --- a/src/bun.js/test/expect/toContainAllValues.zig +++ b/src/bun.js/test/expect/toContainAllValues.zig @@ -48,7 +48,7 @@ pub fn toContainAllValues( } if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalObject); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainAnyKeys.zig b/src/bun.js/test/expect/toContainAnyKeys.zig index 2f8fcf3370..702bf1f631 100644 --- a/src/bun.js/test/expect/toContainAnyKeys.zig +++ b/src/bun.js/test/expect/toContainAnyKeys.zig @@ -41,7 +41,7 @@ pub fn toContainAnyKeys( } if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainAnyValues.zig b/src/bun.js/test/expect/toContainAnyValues.zig index 9a9582b907..6df6f7e317 100644 --- a/src/bun.js/test/expect/toContainAnyValues.zig +++ b/src/bun.js/test/expect/toContainAnyValues.zig @@ -42,7 +42,7 @@ pub fn toContainAnyValues( } if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalObject); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainEqual.zig b/src/bun.js/test/expect/toContainEqual.zig index 64f521ef68..4cb5938d17 100644 --- a/src/bun.js/test/expect/toContainEqual.zig +++ b/src/bun.js/test/expect/toContainEqual.zig @@ -82,7 +82,7 @@ pub fn toContainEqual( } if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainKey.zig b/src/bun.js/test/expect/toContainKey.zig index 9b16897efc..dc4d0227f8 100644 --- a/src/bun.js/test/expect/toContainKey.zig +++ b/src/bun.js/test/expect/toContainKey.zig @@ -28,7 +28,7 @@ pub fn toContainKey( var pass = try value.hasOwnPropertyValue(globalThis, expected); if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalThis); // handle failure diff --git a/src/bun.js/test/expect/toContainKeys.zig b/src/bun.js/test/expect/toContainKeys.zig index 141de5a403..1ce61b67f7 100644 --- a/src/bun.js/test/expect/toContainKeys.zig +++ b/src/bun.js/test/expect/toContainKeys.zig @@ -44,7 +44,7 @@ pub fn toContainKeys( }; if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainValue.zig b/src/bun.js/test/expect/toContainValue.zig index 6c33a7c9ff..82a42953dd 100644 --- a/src/bun.js/test/expect/toContainValue.zig +++ b/src/bun.js/test/expect/toContainValue.zig @@ -33,7 +33,7 @@ pub fn toContainValue( } if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalObject); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toContainValues.zig b/src/bun.js/test/expect/toContainValues.zig index 6a5157b4e9..fbc85a22a3 100644 --- a/src/bun.js/test/expect/toContainValues.zig +++ b/src/bun.js/test/expect/toContainValues.zig @@ -42,7 +42,7 @@ pub fn toContainValues( } if (not) pass = !pass; - if (pass) return thisValue; + if (pass) return this.returnMatcherValue(globalObject); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toEndWith.zig b/src/bun.js/test/expect/toEndWith.zig index 06b51f7218..2dea94ff2c 100644 --- a/src/bun.js/test/expect/toEndWith.zig +++ b/src/bun.js/test/expect/toEndWith.zig @@ -32,7 +32,7 @@ pub fn toEndWith(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toEqual.zig b/src/bun.js/test/expect/toEqual.zig index ff942e03db..2d13557283 100644 --- a/src/bun.js/test/expect/toEqual.zig +++ b/src/bun.js/test/expect/toEqual.zig @@ -18,7 +18,7 @@ pub fn toEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame var pass = try value.jestDeepEquals(expected, globalThis); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure const diff_formatter = DiffFormatter{ diff --git a/src/bun.js/test/expect/toEqualIgnoringWhitespace.zig b/src/bun.js/test/expect/toEqualIgnoringWhitespace.zig index 38cd5331ec..63445469c9 100644 --- a/src/bun.js/test/expect/toEqualIgnoringWhitespace.zig +++ b/src/bun.js/test/expect/toEqualIgnoringWhitespace.zig @@ -60,7 +60,7 @@ pub fn toEqualIgnoringWhitespace(this: *Expect, globalThis: *JSGlobalObject, cal } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toHaveBeenCalled.zig b/src/bun.js/test/expect/toHaveBeenCalled.zig index 51b79f97cb..731c147b31 100644 --- a/src/bun.js/test/expect/toHaveBeenCalled.zig +++ b/src/bun.js/test/expect/toHaveBeenCalled.zig @@ -23,7 +23,7 @@ pub fn toHaveBeenCalled(this: *Expect, globalThis: *JSGlobalObject, callframe: * const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure if (not) { diff --git a/src/bun.js/test/expect/toHaveBeenCalledOnce.zig b/src/bun.js/test/expect/toHaveBeenCalledOnce.zig index cdc054ac0c..e1560e09d6 100644 --- a/src/bun.js/test/expect/toHaveBeenCalledOnce.zig +++ b/src/bun.js/test/expect/toHaveBeenCalledOnce.zig @@ -19,7 +19,7 @@ pub fn toHaveBeenCalledOnce(this: *Expect, globalThis: *JSGlobalObject, callfram const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure if (not) { diff --git a/src/bun.js/test/expect/toHaveBeenCalledTimes.zig b/src/bun.js/test/expect/toHaveBeenCalledTimes.zig index 57dccd9fd1..d04ed60e1a 100644 --- a/src/bun.js/test/expect/toHaveBeenCalledTimes.zig +++ b/src/bun.js/test/expect/toHaveBeenCalledTimes.zig @@ -26,7 +26,7 @@ pub fn toHaveBeenCalledTimes(this: *Expect, globalThis: *JSGlobalObject, callfra const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure if (not) { diff --git a/src/bun.js/test/expect/toHaveBeenCalledWith.zig b/src/bun.js/test/expect/toHaveBeenCalledWith.zig index 9ca450da6f..73eb795b93 100644 --- a/src/bun.js/test/expect/toHaveBeenCalledWith.zig +++ b/src/bun.js/test/expect/toHaveBeenCalledWith.zig @@ -47,7 +47,7 @@ pub fn toHaveBeenCalledWith(this: *Expect, globalThis: *JSGlobalObject, callfram } if (pass != this.flags.not) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } // handle failure diff --git a/src/bun.js/test/expect/toHaveBeenLastCalledWith.zig b/src/bun.js/test/expect/toHaveBeenLastCalledWith.zig index 34a4e65f59..52f08bc9c2 100644 --- a/src/bun.js/test/expect/toHaveBeenLastCalledWith.zig +++ b/src/bun.js/test/expect/toHaveBeenLastCalledWith.zig @@ -43,7 +43,7 @@ pub fn toHaveBeenLastCalledWith(this: *Expect, globalThis: *JSGlobalObject, call } if (pass != this.flags.not) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } // handle failure diff --git a/src/bun.js/test/expect/toHaveBeenNthCalledWith.zig b/src/bun.js/test/expect/toHaveBeenNthCalledWith.zig index c84d729656..4372b9bcb0 100644 --- a/src/bun.js/test/expect/toHaveBeenNthCalledWith.zig +++ b/src/bun.js/test/expect/toHaveBeenNthCalledWith.zig @@ -51,7 +51,7 @@ pub fn toHaveBeenNthCalledWith(this: *Expect, globalThis: *JSGlobalObject, callf } if (pass != this.flags.not) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } // handle failure diff --git a/src/bun.js/test/expect/toHaveLastReturnedWith.zig b/src/bun.js/test/expect/toHaveLastReturnedWith.zig index ad5c242027..97ce3ca406 100644 --- a/src/bun.js/test/expect/toHaveLastReturnedWith.zig +++ b/src/bun.js/test/expect/toHaveLastReturnedWith.zig @@ -46,7 +46,7 @@ pub fn toHaveLastReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfr } if (pass != this.flags.not) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } // Handle failure diff --git a/src/bun.js/test/expect/toHaveLength.zig b/src/bun.js/test/expect/toHaveLength.zig index 275de33dc3..98bd4a5e13 100644 --- a/src/bun.js/test/expect/toHaveLength.zig +++ b/src/bun.js/test/expect/toHaveLength.zig @@ -50,7 +50,7 @@ pub fn toHaveLength( } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure if (not) { diff --git a/src/bun.js/test/expect/toHaveNthReturnedWith.zig b/src/bun.js/test/expect/toHaveNthReturnedWith.zig index 0f7244f7a6..301ed182d0 100644 --- a/src/bun.js/test/expect/toHaveNthReturnedWith.zig +++ b/src/bun.js/test/expect/toHaveNthReturnedWith.zig @@ -55,7 +55,7 @@ pub fn toHaveNthReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfra } if (pass != this.flags.not) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } // Handle failure diff --git a/src/bun.js/test/expect/toHaveProperty.zig b/src/bun.js/test/expect/toHaveProperty.zig index 3013ec4787..9d1c58b745 100644 --- a/src/bun.js/test/expect/toHaveProperty.zig +++ b/src/bun.js/test/expect/toHaveProperty.zig @@ -39,7 +39,7 @@ pub fn toHaveProperty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Ca } if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/src/bun.js/test/expect/toHaveReturned.zig b/src/bun.js/test/expect/toHaveReturned.zig index 75438185fc..b088c02923 100644 --- a/src/bun.js/test/expect/toHaveReturned.zig +++ b/src/bun.js/test/expect/toHaveReturned.zig @@ -43,7 +43,7 @@ inline fn toHaveReturnedTimesFn(this: *Expect, globalThis: *JSGlobalObject, call const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); switch (not) { inline else => |is_not| { diff --git a/src/bun.js/test/expect/toHaveReturnedWith.zig b/src/bun.js/test/expect/toHaveReturnedWith.zig index a7c5de26d6..b362759842 100644 --- a/src/bun.js/test/expect/toHaveReturnedWith.zig +++ b/src/bun.js/test/expect/toHaveReturnedWith.zig @@ -52,7 +52,7 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe: } if (pass != this.flags.not) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } // Handle failure diff --git a/src/bun.js/test/expect/toInclude.zig b/src/bun.js/test/expect/toInclude.zig index 802caf2393..075665ed76 100644 --- a/src/bun.js/test/expect/toInclude.zig +++ b/src/bun.js/test/expect/toInclude.zig @@ -32,7 +32,7 @@ pub fn toInclude(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toIncludeRepeated.zig b/src/bun.js/test/expect/toIncludeRepeated.zig index dbc5eeef8b..66b9e57c98 100644 --- a/src/bun.js/test/expect/toIncludeRepeated.zig +++ b/src/bun.js/test/expect/toIncludeRepeated.zig @@ -57,7 +57,7 @@ pub fn toIncludeRepeated(this: *Expect, globalThis: *JSGlobalObject, callFrame: pass = actual_count == countAsNum; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toMatch.zig b/src/bun.js/test/expect/toMatch.zig index c774969bf5..d3d817ab7f 100644 --- a/src/bun.js/test/expect/toMatch.zig +++ b/src/bun.js/test/expect/toMatch.zig @@ -39,7 +39,7 @@ pub fn toMatch(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame }; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure const expected_fmt = expected_value.toFmt(&formatter); diff --git a/src/bun.js/test/expect/toMatchObject.zig b/src/bun.js/test/expect/toMatchObject.zig index 2804745346..1b72732928 100644 --- a/src/bun.js/test/expect/toMatchObject.zig +++ b/src/bun.js/test/expect/toMatchObject.zig @@ -37,7 +37,7 @@ pub fn toMatchObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal var pass = try received_object.jestDeepMatch(property_matchers, globalThis, true); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure const diff_formatter = DiffFormatter{ diff --git a/src/bun.js/test/expect/toSatisfy.zig b/src/bun.js/test/expect/toSatisfy.zig index dd7f1d3262..20b6a1c181 100644 --- a/src/bun.js/test/expect/toSatisfy.zig +++ b/src/bun.js/test/expect/toSatisfy.zig @@ -32,7 +32,7 @@ pub fn toSatisfy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra const not = this.flags.not; const pass = (result.isBoolean() and result.toBoolean()) != not; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toStartWith.zig b/src/bun.js/test/expect/toStartWith.zig index a457aa6507..760c4502f8 100644 --- a/src/bun.js/test/expect/toStartWith.zig +++ b/src/bun.js/test/expect/toStartWith.zig @@ -32,7 +32,7 @@ pub fn toStartWith(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF const not = this.flags.not; if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; defer formatter.deinit(); diff --git a/src/bun.js/test/expect/toStrictEqual.zig b/src/bun.js/test/expect/toStrictEqual.zig index b74813fe90..86a6a0740b 100644 --- a/src/bun.js/test/expect/toStrictEqual.zig +++ b/src/bun.js/test/expect/toStrictEqual.zig @@ -18,7 +18,7 @@ pub fn toStrictEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal var pass = try value.jestStrictDeepEquals(expected, globalThis); if (not) pass = !pass; - if (pass) return .js_undefined; + if (pass) return this.returnMatcherValue(globalThis); // handle failure const diff_formatter = DiffFormatter{ .received = value, .expected = expected, .globalThis = globalThis, .not = not }; diff --git a/src/bun.js/test/expect/toThrow.zig b/src/bun.js/test/expect/toThrow.zig index 0fd4e1f28c..b340c5ca32 100644 --- a/src/bun.js/test/expect/toThrow.zig +++ b/src/bun.js/test/expect/toThrow.zig @@ -39,7 +39,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame if (not) { const signature = comptime getSignature("toThrow", "expected", true); - if (!did_throw) return .js_undefined; + if (!did_throw) return this.returnMatcherValue(globalThis); const result: JSValue = result_.?; var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -76,7 +76,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame defer expected_slice.deinit(); const received_slice = try received_message.toSliceOrNull(globalThis); defer received_slice.deinit(); - if (!strings.contains(received_slice.slice(), expected_slice.slice())) return .js_undefined; + if (!strings.contains(received_slice.slice(), expected_slice.slice())) return this.returnMatcherValue(globalThis); } return this.throw(globalThis, signature, "\n\nExpected substring: not {any}\nReceived message: {any}\n", .{ @@ -95,7 +95,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame // TODO: REMOVE THIS GETTER! Expose a binding to call .test on the RegExp object directly. if (try expected_value.get(globalThis, "test")) |test_fn| { const matches = test_fn.call(globalThis, expected_value, &.{received_message}) catch |err| globalThis.takeException(err); - if (!matches.toBoolean()) return .js_undefined; + if (!matches.toBoolean()) return this.returnMatcherValue(globalThis); } return this.throw(globalThis, signature, "\n\nExpected pattern: not {any}\nReceived message: {any}\n", .{ @@ -112,12 +112,12 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame if (globalThis.hasException()) return .zero; // no partial match for this case - if (!try expected_message.isSameValue(received_message, globalThis)) return .js_undefined; + if (!try expected_message.isSameValue(received_message, globalThis)) return this.returnMatcherValue(globalThis); return this.throw(globalThis, signature, "\n\nExpected message: not {any}\n", .{expected_message.toFmt(&formatter)}); } - if (!result.isInstanceOf(globalThis, expected_value)) return .js_undefined; + if (!result.isInstanceOf(globalThis, expected_value)) return this.returnMatcherValue(globalThis); var expected_class = ZigString.Empty; try expected_value.getClassName(globalThis, &expected_class); @@ -126,7 +126,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame } if (did_throw) { - if (expected_value == .zero or expected_value.isUndefined()) return .js_undefined; + if (expected_value == .zero or expected_value.isUndefined()) return this.returnMatcherValue(globalThis); const result: JSValue = if (result_.?.toError()) |r| r @@ -146,7 +146,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame defer expected_slice.deinit(); const received_slice = try received_message.toSlice(globalThis, globalThis.allocator()); defer received_slice.deinit(); - if (strings.contains(received_slice.slice(), expected_slice.slice())) return .js_undefined; + if (strings.contains(received_slice.slice(), expected_slice.slice())) return this.returnMatcherValue(globalThis); } // error: message from received error does not match expected string @@ -171,7 +171,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame // TODO: REMOVE THIS GETTER! Expose a binding to call .test on the RegExp object directly. if (try expected_value.get(globalThis, "test")) |test_fn| { const matches = test_fn.call(globalThis, expected_value, &.{received_message}) catch |err| globalThis.takeException(err); - if (matches.toBoolean()) return .js_undefined; + if (matches.toBoolean()) return this.returnMatcherValue(globalThis); } } @@ -202,7 +202,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame } if (is_equal) { - return .js_undefined; + return this.returnMatcherValue(globalThis); } var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; @@ -219,7 +219,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame const signature = comptime getSignature("toThrow", "expected", false); if (_received_message) |received_message| { - if (try received_message.isSameValue(expected_message, globalThis)) return .js_undefined; + if (try received_message.isSameValue(expected_message, globalThis)) return this.returnMatcherValue(globalThis); } // error: message from received error does not match expected error message. @@ -237,7 +237,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame return this.throw(globalThis, signature, "\n\nExpected message: {any}\nReceived value: {any}\n", .{ expected_fmt, received_fmt }); } - if (result.isInstanceOf(globalThis, expected_value)) return .js_undefined; + if (result.isInstanceOf(globalThis, expected_value)) return this.returnMatcherValue(globalThis); // error: received error not instance of received error constructor var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; diff --git a/test/regression/issue/23420.test.ts b/test/regression/issue/23420.test.ts new file mode 100644 index 0000000000..5e34b0621a --- /dev/null +++ b/test/regression/issue/23420.test.ts @@ -0,0 +1,44 @@ +import { expect, test } from "bun:test"; + +test("resolves matcher returns a Promise", () => { + const promise = Promise.resolve(42); + const matcherResult = expect(promise).resolves.toBe(42); + expect(matcherResult).toBeInstanceOf(Promise); + return matcherResult; +}); + +test("rejects matcher returns a Promise", () => { + const promise = Promise.reject(new Error("test error")); + const matcherResult = expect(promise).rejects.toThrow("test error"); + expect(matcherResult).toBeInstanceOf(Promise); + return matcherResult; +}); + +test("resolves.not matcher returns a Promise", () => { + const promise = Promise.resolve(42); + const matcherResult = expect(promise).resolves.not.toBe(100); + expect(matcherResult).toBeInstanceOf(Promise); + return matcherResult; +}); + +test("rejects.not matcher returns a Promise", () => { + const promise = Promise.reject(42); + const matcherResult = expect(promise).rejects.not.toThrow("wrong error"); + expect(matcherResult).toBeInstanceOf(Promise); + return matcherResult; +}); + +test("multiple resolves matchers can be chained with await", async () => { + const promise1 = Promise.resolve(1); + const promise2 = Promise.resolve(2); + + await expect(promise1).resolves.toBe(1); + await expect(promise2).resolves.toBe(2); +}); + +test("resolves.toEqual returns a Promise", async () => { + const promise = Promise.resolve({ foo: "bar" }); + const matcherResult = expect(promise).resolves.toEqual({ foo: "bar" }); + expect(matcherResult).toBeInstanceOf(Promise); + await matcherResult; +});