diff options
author | 2023-06-20 07:39:44 +0200 | |
---|---|---|
committer | 2023-06-19 22:39:44 -0700 | |
commit | e9e0e051569d3858cfc18b21a6aa6d1b7184f7e7 (patch) | |
tree | 3e31f68eb27b1b60c174c8970f11523d378ea43e /test/js | |
parent | 7d94a49ef403750886c2e9ebfc5a7752b8ccb882 (diff) | |
download | bun-e9e0e051569d3858cfc18b21a6aa6d1b7184f7e7.tar.gz bun-e9e0e051569d3858cfc18b21a6aa6d1b7184f7e7.tar.zst bun-e9e0e051569d3858cfc18b21a6aa6d1b7184f7e7.zip |
feat(bun/test): Impl. "toBeArray", "toBeArrayOfSize" & "toBeTypeOf" (#3316)
* Implement toBeArray, toBeArrayOfSize, toBeTypeOf
* fix typos/variable names
* Add testcases for regex and dates
* little fix
* i didn't paste that...
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/test/expect.test.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/js/bun/test/expect.test.ts b/test/js/bun/test/expect.test.ts index 2afb9726c..fba20f1dc 100644 --- a/test/js/bun/test/expect.test.ts +++ b/test/js/bun/test/expect.test.ts @@ -204,6 +204,64 @@ describe("expect()", () => { expect({}).not.toBeNil(); }); + test("toBeArray()", () => { + expect([]).toBeArray(); + expect([1, 2, 3, '🫓']).toBeArray(); + expect(new Array()).toBeArray(); + expect(new Array(1, 2, 3)).toBeArray(); + expect({}).not.toBeArray(); + expect("🫓").not.toBeArray(); + expect(0).not.toBeArray(); + expect(true).not.toBeArray(); + expect(null).not.toBeArray(); + }); + + test("toBeArrayOfSize()", () => { + expect([]).toBeArrayOfSize(0); + expect(new Array()).toBeArrayOfSize(0); + expect([1, 2, 3, '🫓']).toBeArrayOfSize(4); + expect(new Array<string | number>(1, 2, 3, '🫓')).toBeArrayOfSize(4); + expect({}).not.toBeArrayOfSize(1); + expect("").not.toBeArrayOfSize(1); + expect(0).not.toBeArrayOfSize(1) + }); + + test("toBeTypeOf()", () => { + expect("Bun! 🫓").toBeTypeOf("string"); + expect(0).toBeTypeOf("number"); + expect(true).toBeTypeOf("boolean"); + expect([]).toBeTypeOf("object"); + expect({}).toBeTypeOf("object"); + expect(null).toBeTypeOf("object"); + expect(undefined).toBeTypeOf("undefined"); + expect(() => {}).toBeTypeOf("function"); + expect(function () {}).toBeTypeOf("function"); + expect(async () => {}).toBeTypeOf("function"); + expect(async function () {}).toBeTypeOf("function"); + expect(function* () {}).toBeTypeOf("function"); + expect(class {}).toBeTypeOf("function"); + expect(new Array()).toBeTypeOf("object"); + expect(BigInt(5)).toBeTypeOf("bigint"); + expect(/(foo|bar)/g).toBeTypeOf("object"); + expect(new RegExp("(foo|bar)", "g")).toBeTypeOf("object"); + expect(new Date()).toBeTypeOf("object"); + + expect("Bun!").not.toBeTypeOf("number"); + expect(0).not.toBeTypeOf("string"); + expect(true).not.toBeTypeOf("number"); + expect([]).not.toBeTypeOf("string"); + expect({}).not.toBeTypeOf("number"); + expect(null).not.toBeTypeOf("string"); + expect(undefined).not.toBeTypeOf("boolean"); + expect(() => {}).not.toBeTypeOf("string"); + expect(function () {}).not.toBeTypeOf("boolean"); + expect(async () => {}).not.toBeTypeOf("object"); + expect(class {}).not.toBeTypeOf("bigint"); + expect(/(foo|bar)/g).not.toBeTypeOf("string"); + expect(new RegExp("(foo|bar)", "g")).not.toBeTypeOf("number"); + expect(new Date()).not.toBeTypeOf("string"); + }); + test("toBeBoolean()", () => { expect(true).toBeBoolean(); expect(false).toBeBoolean(); |