chaijs / chai

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
https://chaijs.github.io
MIT License
8.15k stars 698 forks source link

`Maximum call stack size exceeded` when assertion fails with cyclic references of `Error.cause` #1645

Closed hi-ogawa closed 1 month ago

hi-ogawa commented 1 month ago

chai: 5.1.1 reproduction: https://stackblitz.com/edit/github-caqski-bm1zja?file=repro.mjs

import * as chai from 'chai';

const e = new Error('hello');
e.cause = e;

chai.expect(e).to.equal(123);
// Error: Maximum call stack size exceeded

For the context, we're thinking to expand on Error equality on Vitest https://github.com/vitest-dev/vitest/pull/5876. Most of the logic is implemented on Vitest side, but we still use chai's assertion error message generation. While making test cases with cyclic references, I found that Error: Maximum call stack size exceeded is likely coming from chai as seen in the repro above.

43081j commented 1 month ago

i've fixed this in chaijs/loupe#82

once that lands, I'll bump the version in chai and get a new patch version published