diff options
author | 2023-08-09 07:25:32 +0200 | |
---|---|---|
committer | 2023-08-08 22:25:32 -0700 | |
commit | 63f58f40267856ef5e8ff3e8b0c5720a6d870873 (patch) | |
tree | a4098acc2ac5339511f9db43666c780fe0d5837a /test/js | |
parent | 009fe18fa269247ae533608fa524c442b69b8f3a (diff) | |
download | bun-63f58f40267856ef5e8ff3e8b0c5720a6d870873.tar.gz bun-63f58f40267856ef5e8ff3e8b0c5720a6d870873.tar.zst bun-63f58f40267856ef5e8ff3e8b0c5720a6d870873.zip |
feat(bun:test) add support for test.each() and describe.each() (#4047)
* rename callback to func
* update testscope to handle function arguments
* works
* big cleanup
* works in debug, not release
* fix memory issue & update tests
* catch & str test
* write types for each() & switch tests to ts
* rm & typo
* move some code around & support describe
* review changes
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/test/jest-each.test.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/js/bun/test/jest-each.test.ts b/test/js/bun/test/jest-each.test.ts new file mode 100644 index 000000000..fc4145cbe --- /dev/null +++ b/test/js/bun/test/jest-each.test.ts @@ -0,0 +1,51 @@ +import { describe, expect, it } from "bun:test"; + +const NUMBERS = [ + [1, 1, 2], + [1, 2, 3], + [2, 1, 3], +]; + +describe("jest-each", () => { + it("check types", () => { + expect(it.each).toBeTypeOf("function"); + expect(it.each([])).toBeTypeOf("function"); + }); + it.each(NUMBERS)("add two numbers", (a, b, e) => { + expect(a + b).toBe(e); + }); + it.each(NUMBERS)("add two numbers with callback", (a, b, e, done) => { + expect(a + b).toBe(e); + expect(done).toBeDefined(); + // We cast here because we cannot type done when typing args as ...T + (done as unknown as (err?: unknown) => void)(); + }); + it.each([ + ["a", "b", "ab"], + ["c", "d", "cd"], + ["e", "f", "ef"], + ])(`adds two strings`, (a, b, res) => { + expect(typeof a).toBe("string"); + expect(typeof b).toBe("string"); + expect(typeof res).toBe("string"); + expect(a.concat(b)).toBe(res); + }); + it.each([ + { a: 1, b: 1, e: 2 }, + { a: 1, b: 2, e: 3 }, + { a: 2, b: 13, e: 15 }, + { a: 2, b: 13, e: 15 }, + { a: 2, b: 123, e: 125 }, + { a: 15, b: 13, e: 28 }, + ])("add two numbers with object", ({ a, b, e }, cb) => { + expect(a + b).toBe(e); + cb(); + }); +}); + +describe.each(["some", "cool", "strings"])("works with describe", s => { + it(`has access to params : ${s}`, done => { + expect(s).toBeTypeOf("string"); + done(); + }); +}); |