-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd Behavior: No Stack Trace and Double Output #1179
Comments
I've got the same issue. This happens because var expect = require('chai').expect;
describe('failed test with cyclic dependencies', function() {
it('should not break Mocha', function() {
var c = {}; c.c = c;
expect({}).to.equal(c);
});
it('should not interfere with other tests', function() {
expect(true).to.be.true;
});
});
// Uncaught TypeError: Converting circular structure to JSON
// at Object.stringify (native)
// at stringify (/usr/local/lib/node_modules/mocha/lib/reporters/base.js:456:15)
// at /usr/local/lib/node_modules/mocha/lib/reporters/base.js:184:33
// at Array.forEach (native)
// ... I temporarily solved this by patching
The most simple solution is to wrap the function stringify(obj) {
if (obj instanceof RegExp) return obj.toString();
try {
return JSON.stringify(obj, null, 2);
} catch (e) {
return '' + obj;
}
} But it would be probably better to modify the function canonicalize(obj, stack) {
stack = stack || [];
// if (utils.indexOf(stack, obj) !== -1) return obj;
if (utils.indexOf(stack, obj) !== -1) return '[Circular]';
var canonicalizedObj;
if ('[object Array]' == {}.toString.call(obj)) {
stack.push(obj);
canonicalizedObj = utils.map(obj, function(item) {
return canonicalize(item, stack);
});
stack.pop();
} else if (typeof obj === 'object' && obj !== null) {
stack.push(obj);
canonicalizedObj = {};
utils.forEach(utils.keys(obj).sort(), function(key) {
canonicalizedObj[key] = canonicalize(obj[key], stack);
});
stack.pop();
} else {
canonicalizedObj = obj;
}
return canonicalizedObj;
} |
You could also use the |
👍 Seeing the same issue with |
Thanks! |
I'm not sure how to go about debugging this scenario. I've narrowed it down to the following snippet. It's plausible that
chai
is causing this, but I don't know enough about the guts of either chai or mocha to figure out which it is.Node v0.10.26, Mocha 1.18.2, Chai 1.9.1
Given
Output
Given
This next bit is probably just an extension of the above issue, but it exhibits slightly weirder behavior.
Output
The text was updated successfully, but these errors were encountered: