Skip to content

Commit

Permalink
feat(test): rejects.toThrow and resolves.toThrow (#7652)
Browse files Browse the repository at this point in the history
  • Loading branch information
paperclover authored Dec 14, 2023
1 parent 8ec405f commit 1fc9b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/bun.js/test/expect.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1702,14 +1702,18 @@ pub const Expect = struct {

const value: JSValue = this.getValue(globalObject, thisValue, "toThrow", "<green>expected<r>") orelse return .zero;

if (!value.jsType().isFunction()) {
globalObject.throw("Expected value must be a function", .{});
return .zero;
}

const not = this.flags.not;

const result_: ?JSValue = brk: {
if (!value.jsType().isFunction()) {
if (this.flags.promise != .none) {
break :brk value;
}

globalObject.throw("Expected value must be a function", .{});
return .zero;
}

var vm = globalObject.bunVM();
var return_value: JSValue = .zero;

Expand Down
3 changes: 2 additions & 1 deletion test/js/bun/test/expect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("expect()", () => {
await expect(Promise.reject({ a: 1, b: 2 })).rejects.toMatchObject({ a: 1 });
await expect(Promise.reject({ a: 1, b: 2 })).rejects.not.toMatchObject({ c: 1 });
await expect(Promise.reject(new Error("rejectMessage"))).rejects.toMatchObject({ message: "rejectMessage" });
//await expect(Promise.reject(new Error())).rejects.toThrow(); // FIXME
await expect(Promise.reject(new Error())).rejects.toThrow();

// not receiving a rejected promise -> should throw
if (isBun) {
Expand Down Expand Up @@ -82,6 +82,7 @@ describe("expect()", () => {
throw new Error();
}),
).resolves.toThrow();
await expect(Promise.resolve(new Error())).resolves.toThrow();

// not receiving a resolved promise -> should throw
if (isBun) {
Expand Down

0 comments on commit 1fc9b56

Please sign in to comment.