☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix: handle empty null-prototyped objects (#5506)
Alex Anderson2a0bce02f6f6
diff --git a/lib/utils.js b/lib/utils.jsindex d3a928b8..ecfefd92 100644--- a/lib/utils.js+++ b/lib/utils.js@@ -108,6 +108,7 @@ function emptyRepresentation(value, typeHint) {switch (typeHint) {case "function":return "[Function]";+ case "null-prototype":case "object":return "{}";case "array":diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.jsindex 2a7356b5..150a998a 100644--- a/test/unit/utils.spec.js+++ b/test/unit/utils.spec.js@@ -290,6 +290,13 @@ describe("lib/utils", function () {});describe("should represent null prototypes", function () {+ it("Without properties", function () {+ const foo = Object.create(null, {});+ const expected = "{}";++ expect(stringify(foo), "to be", expected);+ });+it("With explicit names", function () {const foo = Object.create(null, {[Symbol.toStringTag]: { value: "Foo" },