Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Merge 9ae2a1b into e913a41
Browse files Browse the repository at this point in the history
  • Loading branch information
variousauthors committed Oct 23, 2018
2 parents e913a41 + 9ae2a1b commit a085484
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions specs/validate-helpers-spec.js
Expand Up @@ -202,6 +202,25 @@ describe("validate", function() {
expect(validate.prettify(object)).toEqual("Custom string");
});

it("tries to stringify objects that don't implement toString", function() {
var object = Object.create(null);

object.name = "Foo Bar";

expect(validate.prettify(object)).toEqual("{\"name\":\"Foo Bar\"}");
});

it("throws an error when trying to parse cyclical structures", function() {
var object = Object.create(null);

object.name = "Foo Bar";
object.cycle = object;

expect(function () {
return validate.prettify(object);
}).toThrow();
});

it("doesn't allow too many decimals", function() {
expect(validate.prettify(4711)).toEqual("4711");
expect(validate.prettify(4711.2)).toEqual("4711.2");
Expand Down
4 changes: 4 additions & 0 deletions validate.js
Expand Up @@ -387,6 +387,10 @@
}

if (v.isObject(str)) {
if (!v.isDefined(str.toString)) {
return JSON.stringify(str);
}

return str.toString();
}

Expand Down

0 comments on commit a085484

Please sign in to comment.