Closed oleg-codaio closed 7 years ago
Hi @vaskevich! Can you write a test that shows that problem or bug?
Hey @eagleeye - sorry for the delay; this fell off my radar!
Sure, here's a simple, contrived test case that fails with a stack overflow:
'use strict';
const testHelper = require('../../test_helper');
describe('Subset test', () => {
it('should pass', () => {
const child = {};
const parent = {
children: [child],
};
child.parent = parent;
const myObject = {
a: 1,
b: 'two',
c: parent,
};
assert.containSubset(myObject, {
a: 1,
c: parent,
});
});
});
Essentially, parent
and child
are circular data structures, and because containSubset
keeps trying to recurse down, this test results in a stack overflow. With the proposed change, the test would pass, and that change also serves as an optimization as well.
bump!
@vaskevich Thanks! Published as chai-subset@1.5.0 with test that you provided!
Woohoo! 🙌
If two objects are the same, then inherently they're subsets of each other. This also fixes a bug I've run into with testing recursive data structures.