Last active
December 28, 2015 15:38
-
-
Save paolocarrasco/7522670 to your computer and use it in GitHub Desktop.
A way to solve the problem of JSON.stringify "serialize cyclic structures" in mocha-phantomjs (https://github.com/metaskills/mocha-phantomjs/issues/104). Required only if you're printing in the console objects with cyclic structures (not very common).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('functionalityToTest', function() { | |
var stringify = JSON.stringify; | |
before(function() { | |
JSON.stringify = function(obj) { | |
var seen = []; | |
return stringify(obj, function(key, val) { | |
if (typeof val == "object") { | |
if (seen.indexOf(val) >= 0) { return; } | |
seen.push(val); | |
} | |
return val; | |
}); | |
}; | |
}); | |
after(function() { | |
JSON.stringify = stringify; | |
}); | |
// tests go here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment