From 5e584e9a547b9290ae7a6800d914223fe0c3d8a6 Mon Sep 17 00:00:00 2001 From: Don Isaac Date: Fri, 10 Jan 2025 05:05:05 -0600 Subject: [PATCH] fix(test): toThrow() === toThrow('') (#16308) --- src/bun.js/test/expect.zig | 4 ++++ test/cli/test/expectations.test.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/cli/test/expectations.test.ts diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index f90c8bbd15f50a..f09abb158fb256 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -2172,6 +2172,10 @@ pub const Expect = struct { break :brk innerConstructorValue; } } + } else if (value.isString()) { + // `.toThrow("") behaves the same as `.toThrow()` + const s = value.toString(globalThis); + if (s.length() == 0) break :brk .zero; } break :brk value; }; diff --git a/test/cli/test/expectations.test.ts b/test/cli/test/expectations.test.ts new file mode 100644 index 00000000000000..20698874daf454 --- /dev/null +++ b/test/cli/test/expectations.test.ts @@ -0,0 +1,11 @@ +describe(".toThrow()", () => { + it(".toThrow() behaves the same as .toThrow('')", () => { + expect(() => { + throw new Error("test"); + }).toThrow(); + + expect(() => { + throw new Error("test"); + }).toThrow(""); + }); +});