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

Deep equals on array of functions does not work as expected #896

Closed
alidcast opened this issue Jan 2, 2017 · 2 comments
Closed

Deep equals on array of functions does not work as expected #896

alidcast opened this issue Jan 2, 2017 · 2 comments

Comments

@alidcast
Copy link

alidcast commented Jan 2, 2017

The following code returns false:

    let q = new Queue()
    q.add(1, 'string', function () { })
    let removed = q.remove(3)
    expect(removed).to.deep.equal([1, 'string', function () { }])

But if I run it without the functions, it returns true.

The failed message reads:

expected [ 1, 'string', [Function] ] to deeply equal [ 1, 'string', [Function] ]
@meeber
Copy link
Contributor

meeber commented Jan 2, 2017

Hi @alidcastano. I think you're running into the same issue as described in #697. Essentially, functions are checked for referential equality, so function () {} isn't considered deeply equal to function () {}. The conversation in #697 goes into more detail about why it is that way, but here are two examples that demonstrate it:

it("same function", function () {
  let noop = function () {};

  expect([1, 'string', noop]).to.deep.equal([1, 'string', noop]);  // passes
});

it("different functions", function () {
  expect([1, 'string', function () {}]).to.deep.equal([1, 'string', function () {}]);  // fails
});

@alidcast
Copy link
Author

alidcast commented Jan 2, 2017

That definitely explains it, thanks.

@alidcast alidcast closed this as completed Jan 2, 2017
skjnldsv added a commit to nextcloud/contacts that referenced this issue Oct 27, 2017
See chaijs/chai#896

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
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