Skip to content
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

Mocha.utils.stringify() hangs on recursive data structures #2751

Closed
oleg-codaio opened this issue Mar 24, 2017 · 2 comments
Closed

Mocha.utils.stringify() hangs on recursive data structures #2751

oleg-codaio opened this issue Mar 24, 2017 · 2 comments

Comments

@oleg-codaio
Copy link

oleg-codaio commented Mar 24, 2017

I'm using Chai, and often use assert.deepEqual() to make sure that one object is equal to another. This works as expected, but to print out the diff, Chai uses Mocha.utils.stringify(). When there are recursive objects involved, however, the whole tests fails at this point, so I've had to use this fix in my tests:

const util = require('util');
Mocha.utils.stringify = value => util.inspect(value, {depth: 5});

That prevents the test from hanging, but doesn't always work as well as Mocha's stringify function.

As an example of a test that would hang, consider:

it('should fail', () => {
  const a = {};
  const b = {a};
  a.b = b;
  assert.deepEqual(b, {});  // Expected to fail, but instead the whole test suite hangs.
});
@ScottFreeCode
Copy link
Contributor

I am unable to reproduce this; I get "AssertionError: expected { a: { b: [Circular] } } to deeply equal {}"

We do still have a few issues involving circular references, though none of them appear to involve hanging that I notice:
#2598
#2559

@oleg-codaio
Copy link
Author

oleg-codaio commented Mar 28, 2017

Ah sorry, I never bothered testing to make sure this failed. :( It appears the issue has something to do with some more complex objects, perhaps containing getters or Proxies. Closing this for now, and will re-open if I find time to find the root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants