var Sinon = require("sinon")
var stringify = require("..")
function jsonify(obj) { return JSON.stringify(obj, null, 2) }
describe("Stringify", function() {
it("must stringify circular objects", function() {
var obj = {name: "Alice"}
obj.self = obj
var json = stringify(obj, null, 2)
json.must.eql(jsonify({name: "Alice", self: "[Circular ~]"}))
})
it("must stringify circular objects with intermediaries", function() {
var obj = {name: "Alice"}
obj.identity = {self: obj}
var json = stringify(obj, null, 2)
json.must.eql(jsonify({name: "Alice", identity: {self: "[Circular ~]"}}))
})
it("must stringify circular objects deeper", function() {
var obj = {name: "Alice", child: {name: "Bob"}}
obj.child.self = obj.child
stringify(obj, null, 2).must.eql(jsonify({
name: "Alice",
child: {name: "Bob", self: "[Circular ~.child]"}
}))
})
it("must stringify circular objects deeper with intermediaries", function() {
var obj = {name: "Alice", child: {name: "Bob"}}
obj.child.identity = {self: obj.child}
stringify(obj, null, 2).must.eql(jsonify({
name: "Alice",
child: {name: "Bob", identity: {self: "[Circular ~.child]"}}
}))
})
it("must stringify circular objects in an array", function() {
var obj = {name: "Alice"}
obj.self = [obj, obj]
stringify(obj, null, 2).must.eql(jsonify({
name: "Alice", self: ["[Circular ~]", "[Circular ~]"]
}))
})
it("must stringify circular objects deeper in an array", function() {
var obj = {name: "Alice", children: [{name: "Bob"}, {name: "Eve"}]}
obj.children[0].self = obj.children[0]