This commit is contained in:
pfg
2025-07-31 17:59:19 -07:00
parent 5277d38423
commit 0800a4cee5
2 changed files with 34 additions and 6 deletions

View File

@@ -2455,12 +2455,16 @@ pub const Expect = struct {
var return_value_from_function: JSValue = .zero;
if (!value.jsType().isFunction()) {
if (this.flags.promise != .none) {
if (value.isAnyError()) {
return .{ value, return_value_from_function };
} else {
return .{ null, return_value_from_function };
}
switch (this.flags.promise) {
.none => {},
.rejects => return .{ value, return_value_from_function },
.resolves => {
if (value.isAnyError()) {
return .{ value, return_value_from_function };
} else {
return .{ null, return_value_from_function };
}
},
}
return globalThis.throw("Expected value must be a function", .{});

View File

@@ -17,3 +17,27 @@ test("resolves not toThrow", async () => {
await expect(Promise.resolve(new Error("abc"))).resolves.toThrow("abc");
await expect(Promise.reject(new Error("abc"))).rejects.toThrow("abc");
});
test("doesn't break rejects", () => {
expect(
(async () => {
throw new DOMException("123");
})(),
).rejects.toThrow("123");
});
test("doesn't break rejects null", () => {
expect(
(async () => {
throw null;
})(),
).rejects.toThrow();
});
test("resolves null doesn't throw", () => {
expect(
(async () => {
return null;
})(),
).resolves.not.toThrow();
});