diff options
author | 2023-06-26 15:49:14 -0700 | |
---|---|---|
committer | 2023-06-26 15:49:26 -0700 | |
commit | a5100ad380f099907d4b3a9bec696f481b8e7821 (patch) | |
tree | 3a4f9c9320b19657b0d2b738ed791b4978bdbf20 | |
parent | 16598555f137112a3df2da5d8f2ee8edb496484f (diff) | |
download | bun-a5100ad380f099907d4b3a9bec696f481b8e7821.tar.gz bun-a5100ad380f099907d4b3a9bec696f481b8e7821.tar.zst bun-a5100ad380f099907d4b3a9bec696f481b8e7821.zip |
Fix .rejects
Diffstat (limited to '')
-rw-r--r-- | src/bun.js/test/expect.zig | 21 | ||||
-rw-r--r-- | test/js/bun/test/expect.test.js | 22 |
2 files changed, 29 insertions, 14 deletions
diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 90fcb2a73..e0833f8ed 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -73,32 +73,25 @@ pub const Expect = struct { } pub fn getResolves(this: *Expect, thisValue: JSValue, globalThis: *JSGlobalObject) callconv(.C) JSValue { - switch (this.flags.promise) { + this.flags.promise = switch (this.flags.promise) { + .resolves, .none => .resolves, .rejects => { globalThis.throw("Cannot chain .resolves() after .rejects()", .{}); return .zero; }, - .resolves => {}, - .none => { - this.flags.promise = .resolves; - }, - } + }; + return thisValue; } pub fn getRejects(this: *Expect, thisValue: JSValue, globalThis: *JSGlobalObject) callconv(.C) JSValue { - switch (this.flags.promise) { - .rejects => { - this.flags.promise = .rejects; - }, + this.flags.promise = switch (this.flags.promise) { + .none, .rejects => .rejects, .resolves => { globalThis.throw("Cannot chain .rejects() after .resolves()", .{}); return .zero; }, - .none => { - this.flags.promise = .resolves; - }, - } + }; return thisValue; } diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js index d42ec2219..e7195d6f8 100644 --- a/test/js/bun/test/expect.test.js +++ b/test/js/bun/test/expect.test.js @@ -6,6 +6,28 @@ var { isBun, test, describe, expect, jest, vi, mock, bunTest, spyOn } = require("./test-interop.js")(); describe("expect()", () => { + test("rejects", async () => { + await expect(Promise.reject(1)).rejects.toBe(1); + + // Different task + await expect( + new Promise((_, reject) => { + setTimeout(() => reject(1), 0); + }), + ).rejects.toBe(1); + }); + + test("resolves", async () => { + await expect(Promise.resolve(1)).resolves.toBe(1); + + // Different task + await expect( + new Promise(resolve => { + setTimeout(() => resolve(1), 0); + }), + ).resolves.toBe(1); + }); + test("can call without an argument", () => { expect().toBe(undefined); }); |