mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
fix
This commit is contained in:
@@ -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", .{});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user