diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 0cba01b714..8864161405 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -4543,7 +4543,11 @@ pub const JSValue = enum(JSValueReprInt) { }; pub fn determineDiffMethod(this: JSValue, other: JSValue, global: *JSGlobalObject) DiffMethod { - if ((this.isString() and other.isString()) or (this.isBuffer(global) and other.isBuffer(global))) return .character; + if ((this.isString() and other.isString())) { + if (this.toString(global).is8Bit() and other.toString(global).is8Bit()) return .character; + return .none; + } + if (this.isBuffer(global) and other.isBuffer(global)) return .character; if ((this.isRegExp() and other.isObject()) or (this.isObject() and other.isRegExp())) return .character; if (this.isObject() and other.isObject()) return .line; diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js index 53068d2244..b753ea62f4 100644 --- a/test/js/bun/test/expect.test.js +++ b/test/js/bun/test/expect.test.js @@ -1914,6 +1914,22 @@ describe("expect()", () => { expect(1).not.toBe("1"); expect("hello test").toBe("hello test"); expect("hello test").not.toBe("hello test2"); + + expect(() => { + expect("🟢🟢🟢").toBe("🔴🔴🔴"); + }).toThrow("🔴🔴🔴"); + expect(() => { + expect(String("🟢🟢🟢")).toBe(String("🔴🔴🔴")); + }).toThrow("🔴🔴🔴"); + expect(() => { + expect(new String("🟢🟢🟢")).toBe(String("🔴🔴🔴")); + }).toThrow("🔴🔴🔴"); + expect(() => { + expect(String("🟢🟢🟢")).toBe(new String("🔴🔴🔴")); + }).toThrow("🔴🔴🔴"); + expect(() => { + expect(new String("🟢🟢🟢")).toBe(new String("🔴🔴🔴")); + }).toThrow("🔴🔴🔴"); }); test("toHaveLength()", () => {