From acf4bb71a69985bf6ededa410c9f8bcd36b8b8a8 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Thu, 2 Nov 2023 16:44:21 -0700 Subject: [PATCH] don't character diff emojis --- src/bun.js/bindings/bindings.zig | 6 +++++- test/js/bun/test/expect.test.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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()", () => {