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

Introduce strict equality check in compare() #57

Merged
merged 1 commit into from Mar 2, 2017

Conversation

oleg-codaio
Copy link
Contributor

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.

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.
@eagleeye
Copy link
Contributor

Hi @vaskevich! Can you write a test that shows that problem or bug?

@oleg-codaio
Copy link
Contributor Author

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.

@oleg-codaio
Copy link
Contributor Author

bump!

@eagleeye eagleeye merged commit 5fee046 into debitoor:master Mar 2, 2017
@eagleeye
Copy link
Contributor

eagleeye commented Mar 2, 2017

@vaskevich Thanks! Published as chai-subset@1.5.0 with test that you provided!

@oleg-codaio oleg-codaio deleted the patch-1 branch March 2, 2017 18:42
@oleg-codaio
Copy link
Contributor Author

Woohoo! 🙌

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

Successfully merging this pull request may close these issues.

None yet

2 participants