PrettyPrinter handles objects with invalid toString implementations

This commit is contained in:
Elliot Nelson
2019-05-20 09:01:10 -04:00
parent e04d3d8a62
commit 9f704b6f3a
2 changed files with 29 additions and 0 deletions

View File

@@ -333,4 +333,27 @@ describe("jasmineUnderTest.pp", function () {
expect(jasmineUnderTest.pp(obj)).toEqual("null({ foo: 'bar' })");
});
it("should gracefully handle objects with invalid toString implementations", function () {
var obj = {
foo: {
toString: function() {
// Invalid: toString returning a number
return 3;
}
},
bar: {
toString: function() {
// Invalid: toString returning an object
return new Error("bar");
}
},
// Valid: an actual number
baz: 3,
// Valid: an actual Error object
qux: new Error("bar")
};
expect(jasmineUnderTest.pp(obj)).toEqual("Object({ foo: [object Number], bar: [object Error], baz: 3, qux: Error: bar })");
});
});