aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-09 03:25:41 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-09 03:25:41 -0800
commitc30a110641fd82a0d8368dc3eb6cf226f1764e12 (patch)
tree7460cb84d000c3191a5f9c9e7383dd141253335a
parentced6201cb0433c11d8b7ca9e60de61b133cc8fab (diff)
downloadbun-c30a110641fd82a0d8368dc3eb6cf226f1764e12.tar.gz
bun-c30a110641fd82a0d8368dc3eb6cf226f1764e12.tar.zst
bun-c30a110641fd82a0d8368dc3eb6cf226f1764e12.zip
Cleanup code in expectToThrow
Diffstat (limited to '')
-rw-r--r--src/bun.js/javascript.zig10
-rw-r--r--src/bun.js/test/jest.zig27
2 files changed, 25 insertions, 12 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 713ab7264..9ba56fffa 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -571,6 +571,16 @@ pub const VirtualMachine = struct {
this.eventLoop().tick();
}
+ pub fn waitFor(this: *VirtualMachine, cond: *bool) void {
+ while (!cond.*) {
+ this.eventLoop().tick();
+
+ if (!cond.*) {
+ this.eventLoop().autoTick();
+ }
+ }
+ }
+
pub fn waitForPromise(this: *VirtualMachine, promise: JSC.AnyPromise) void {
this.eventLoop().waitForPromise(promise);
}
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