aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar LongYinan <lynweklm@gmail.com> 2023-09-20 10:11:41 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-20 10:11:41 -0700
commit8c612adcdb04cdc71a464c9a8df4bd871eaffc7d (patch)
treec3be17dff779121a0c2133de09d4d9bdf239498d
parent711a2bcdd1a6bb7ab9029625b28517254cfdcd3e (diff)
downloadbun-8c612adcdb04cdc71a464c9a8df4bd871eaffc7d.tar.gz
bun-8c612adcdb04cdc71a464c9a8df4bd871eaffc7d.tar.zst
bun-8c612adcdb04cdc71a464c9a8df4bd871eaffc7d.zip
Treat `undefined` value as empty in expect.toThrow (#5788)
Fix: https://github.com/napi-rs/napi-rs/blob/main/examples/napi/__tests__/test.framework.js#L16-L19
-rw-r--r--src/bun.js/test/expect.zig6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig
index 6434e3702..04b8670d2 100644
--- a/src/bun.js/test/expect.zig
+++ b/src/bun.js/test/expect.zig
@@ -1697,7 +1697,7 @@ pub const Expect = struct {
const result: JSValue = result_.?;
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject, .quote_strings = true };
- if (expected_value.isEmpty()) {
+ if (expected_value.isEmpty() or expected_value.isUndefined()) {
const signature_no_args = comptime getSignature("toThrow", "", true);
if (result.toError()) |err| {
const name = err.get(globalObject, "name") orelse JSValue.undefined;
@@ -1780,7 +1780,7 @@ pub const Expect = struct {
const signature = comptime getSignature("toThrow", "<green>expected<r>", false);
if (did_throw) {
- if (expected_value.isEmpty()) return thisValue;
+ if (expected_value.isEmpty() or expected_value.isUndefined()) return thisValue;
const result: JSValue = if (result_.?.toError()) |r|
r
@@ -1915,7 +1915,7 @@ pub const Expect = struct {
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject, .quote_strings = true };
const received_line = "Received function did not throw\n";
- if (expected_value.isEmpty()) {
+ if (expected_value.isEmpty() or expected_value.isUndefined()) {
const fmt = comptime getSignature("toThrow", "", false) ++ "\n\n" ++ received_line;
if (Output.enable_ansi_colors) {
globalObject.throw(Output.prettyFmt(fmt, true), .{});