diff options
author | 2023-01-09 03:25:41 -0800 | |
---|---|---|
committer | 2023-01-09 03:25:41 -0800 | |
commit | c30a110641fd82a0d8368dc3eb6cf226f1764e12 (patch) | |
tree | 7460cb84d000c3191a5f9c9e7383dd141253335a /src/bun.js/test/jest.zig | |
parent | ced6201cb0433c11d8b7ca9e60de61b133cc8fab (diff) | |
download | bun-c30a110641fd82a0d8368dc3eb6cf226f1764e12.tar.gz bun-c30a110641fd82a0d8368dc3eb6cf226f1764e12.tar.zst bun-c30a110641fd82a0d8368dc3eb6cf226f1764e12.zip |
Cleanup code in expectToThrow
Diffstat (limited to '')
-rw-r--r-- | src/bun.js/test/jest.zig | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 68469c7e8..dd7299668 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -1117,24 +1117,27 @@ pub const Expect = struct { } const not = this.op.contains(.not); - const result = value.call(globalObject, &.{}).toError_(); - if (result == .zero) { - if (not) return thisValue; - globalObject.throw("Expected function to throw", .{}); - return .zero; - } else if (not) { - globalObject.throw("Expected function not to throw", .{}); + const result_ = value.call(globalObject, &.{}).toError(); + const did_throw = result_ != null; + const matched_expectation = did_throw == !not; + if (matched_expectation) return thisValue; + + if (expected_value.isEmptyOrUndefinedOrNull()) { + if (did_throw) + globalObject.throw("Expected function to throw", .{}) + else + globalObject.throw("Expected function not to throw", .{}); + return .zero; } + const result = result_.?; - if (expected_value == .zero or !expected_value.isCell()) return thisValue; - - const expected_error = expected_value.toError() orelse expected_value; + const expected_error = expected_value.toError(); - if (expected_value.isString() or !expected_error.isUndefined()) { + if (expected_value.isString() or expected_error != null) { const expected = brk: { if (expected_value.isString()) break :brk expected_value; - break :brk expected_error.get(globalObject, "message"); + break :brk expected_error.?.get(globalObject, "message"); }; const actual = result.get(globalObject, "message"); // TODO support partial match |