Skip to content

Commit d786a63

Browse files
committed
diffJson: Test that a circular reference causes JSON.stringify to throw (rather than an infinite loop).
1 parent a9191cb commit d786a63

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: test/diffTest.js

+11
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ describe('#diffJson', function() {
159159
{a: 123, b: 456, c: 789});
160160
diff.convertChangesToXML(diffResult).should.equal('{\n &quot;a&quot;: 123,\n &quot;b&quot;: 456,\n<ins> &quot;c&quot;: 789\n</ins>}');
161161
});
162+
163+
it('should throw an error if one of the objects being diffed has a circular reference', function() {
164+
var circular = {foo: 123};
165+
circular.bar = circular;
166+
(function () {
167+
diff.diffJson(
168+
circular,
169+
{foo: 123, bar: {}}
170+
);
171+
}).should.throw('Converting circular structure to JSON');
172+
});
162173
});
163174

164175
describe('convertToDMP', function() {

0 commit comments

Comments
 (0)