diff --git a/bower.json b/bower.json index 297e4e9..170d769 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "lazy-ass", "main": "index.js", - "version": "0.5.2", + "version": "0.5.3", "homepage": "https://github.com/bahmutov/lazy-ass", "license": "MIT", "ignore": [ diff --git a/index.js b/index.js index e5f3477..c03aad5 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,13 @@ if (arg instanceof Error) { return total + arg.name + ' ' + arg.message; } - return total + JSON.stringify(arg, null, 2); + var argString; + try { + argString = JSON.stringify(arg, null, 2); + } catch (err) { + argString = '[cannot stringify arg ' + k + ']'; + } + return total + argString; }, ''); return msg; } diff --git a/package.json b/package.json index e9daea1..c006cdd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lazy-ass", "description": "Lazy assertions without performance penalty", - "version": "0.5.2", + "version": "0.5.3", "author": "Gleb Bahmutov ", "bugs": { "url": "https://github.com/bahmutov/lazy-ass/issues" diff --git a/test/lazy-ass.spec.js b/test/lazy-ass.spec.js index adbde1c..389887a 100644 --- a/test/lazy-ass.spec.js +++ b/test/lazy-ass.spec.js @@ -164,6 +164,22 @@ }); }); + describe('serializes circular objects', function () { + var foo = { + bar: 'bar' + }; + foo.foo = foo; + + it('can handle circular object', function () { + var msg = 'foo has circular reference'; + expect(function () { + lazyAss(false, msg, foo); + }).to.throwException(function (err) { + expect(err.message).to.contain(msg); + }); + }); + }); + describe('serialize arguments', function () { function foo() { la(false, arguments);