diff options
author | 2023-07-30 10:17:02 +0200 | |
---|---|---|
committer | 2023-07-30 01:17:02 -0700 | |
commit | 40a9ba63409694443058f558df2e480a8f16ff54 (patch) | |
tree | 9f9dc46fa5cff3da8abeeeed37562c0aeaa77159 | |
parent | 681be10294c19b8ce402ec44df5cd6554e2c86c0 (diff) | |
download | bun-40a9ba63409694443058f558df2e480a8f16ff54.tar.gz bun-40a9ba63409694443058f558df2e480a8f16ff54.tar.zst bun-40a9ba63409694443058f558df2e480a8f16ff54.zip |
Improv. (#3885)
-rw-r--r-- | src/bun.js/test/expect.zig | 29 | ||||
-rw-r--r-- | test/js/bun/test/expect.test.js | 22 | ||||
-rw-r--r-- | test/js/bun/test/jest-extended.test.js | 24 |
3 files changed, 38 insertions, 37 deletions
diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 07fbca03c..c56818efc 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -28,6 +28,17 @@ pub const Counter = struct { actual: u32 = 0, }; +const JSTypeOfMap = bun.ComptimeStringMap([]const u8, .{ + .{ "function", "function" }, + .{ "object", "object" }, + .{ "bigint", "bigint" }, + .{ "boolean", "boolean" }, + .{ "number", "number" }, + .{ "string", "string" }, + .{ "symbol", "symbol" }, + .{ "undefined", "undefined" }, +}); + pub var active_test_expectation_counter: Counter = .{}; /// https://jestjs.io/docs/expect @@ -316,7 +327,7 @@ pub const Expect = struct { } else { _msg = ZigString.fromBytes("passes by .pass() assertion"); } - + active_test_expectation_counter.actual += 1; const not = this.flags.not; @@ -364,12 +375,12 @@ pub const Expect = struct { globalObject.throwInvalidArgumentType("fail", "message", "string"); return .zero; } - + value.toZigString(&_msg, globalObject); } else { _msg = ZigString.fromBytes("fails by .fail() assertion"); } - + active_test_expectation_counter.actual += 1; const not = this.flags.not; @@ -2317,15 +2328,7 @@ pub const Expect = struct { return .zero; } - if (!std.mem.eql(u8, expectedAsStr, "function") and - !std.mem.eql(u8, expectedAsStr, "object") and - !std.mem.eql(u8, expectedAsStr, "bigint") and - !std.mem.eql(u8, expectedAsStr, "boolean") and - !std.mem.eql(u8, expectedAsStr, "number") and - !std.mem.eql(u8, expectedAsStr, "string") and - !std.mem.eql(u8, expectedAsStr, "symbol") and - !std.mem.eql(u8, expectedAsStr, "undefined")) - { + if (!JSTypeOfMap.has(expectedAsStr)) { globalThis.throwInvalidArguments("toBeTypeOf() requires a valid type string argument ('function', 'object', 'bigint', 'boolean', 'number', 'string', 'symbol', 'undefined')", .{}); return .zero; } @@ -2356,7 +2359,7 @@ pub const Expect = struct { return .zero; } - pass = std.mem.eql(u8, expectedAsStr, whatIsTheType); + pass = strings.eql(expectedAsStr, whatIsTheType); if (not) pass = !pass; if (pass) return thisValue; diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js index ed94b7e9a..397afd0d9 100644 --- a/test/js/bun/test/expect.test.js +++ b/test/js/bun/test/expect.test.js @@ -2898,28 +2898,6 @@ 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(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"); diff --git a/test/js/bun/test/jest-extended.test.js b/test/js/bun/test/jest-extended.test.js index 5f84914f1..30527e157 100644 --- a/test/js/bun/test/jest-extended.test.js +++ b/test/js/bun/test/jest-extended.test.js @@ -114,8 +114,28 @@ describe("jest-extended", () => { // Array - // test('toBeArray()') - // test('toBeArrayOfSize()') + 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(1, 2, 3, "🫓")).toBeArrayOfSize(4); + expect({}).not.toBeArrayOfSize(1); + expect("").not.toBeArrayOfSize(1); + expect(0).not.toBeArrayOfSize(1); + }); + // test('toIncludeAllMembers()') // test('toIncludeAllPartialMembers()') // test('toIncludeAnyMembers()') |