question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

expect(array).to.deep.include({...}) does not apply deep equality recursively

See original GitHub issue

As the title says, if I run expect(array).to.deep.include(obj) I would expect to apply deep equality to each of the property of obj.

But it does not behave like this, is it a bug?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

14reactions
deksdencommented, Aug 4, 2017

This fails with assert on chai v4.1.0: expect([ { id: 1, name: 'first'}, { id: 2, name: 'second'}]).to.deep.include({ name: 'first' })

AssertionError: expected [ Array(2) ] to deep include { name: ‘first’ }

This is bug? How i can test if array include object with some specified properties?

upd: can be fixed with chai-subset plugin. Code is something like:

expect([ { id: 1, name: 'first'}, { id: 2, name: 'second'}]).to.containSubset([{ name: 'first' }])

4reactions
iraklisgcommented, Aug 9, 2017

@deksden chai-subset plugin is what I was looking for 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chai deep.include throws Error "Uncaught AssertionError
I'm running tests with mocha and chai. res.body.data is an object array.
Read more >
Developers - expect(array).to.deep.include({...}) does not apply deep ...
As the title says, if I run expect(array).to.deep.include(obj) I would expect to apply deep equality to each of the property of obj ....
Read more >
Deep Equality with Pester - Medium
The Recursive Step is when we encounter a complex type and need to call our function on each item within the array or...
Read more >
Testing JS & JSON Objects, Arrays, Object Arrays, Nested ...
When using this approach, rather than having referential equality ( a === b ), it will check an object's keys recursively until it...
Read more >
5 Different Ways to Deep Compare JavaScript Objects
Object comparison in JavaScript is not as easy as comparing primitive data types. This article showcases five ways to deep compare JS ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found