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.

test array to include an object with a certain key: value

See original GitHub issue

Hello,

As the title says we found our selves in a situation where we need to check if an array contains an element that one of his properties equals to something.

We tried and search for a couple of hours until we desided to raise an issue about it. We were able to solve the problem like this:

const playersRegs = created.gameLog.filter(e => e.nameType === eventTypes.PlayerReg);
expect(playersRegs).to.have.lengthOf(1);

but we were hoping for something a bit like:

expect(created.gameLog).to.include.something.that.has.property('nameType', eventTypes.PlayerReg);

if we missed anything please let us know and if we didnt please consider adding this functionality 😉

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
jessicabyrnecommented, Nov 5, 2019

@keithamus Is there a solution available through chai now?

1reaction
meebercommented, Aug 10, 2017

Makes sense. In a case like this one, I can understand accepting decreased precision in exchange for increased maintainability.

A couple of weeks ago I was thinking about the level of effort of making the chai-things plugin compatible with Chai v4. The current stance is we’d wait for #585 to be resolved before fixing chai-things, but that feels like a long ways away to me. Given that the plugin is basically unusable at the moment, I think it might be worth it to fix the plugin directly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test array to include an object with a certain key: value
You can use .some() instead: const hasPlayersReg = created.gameLog.some(e => e.nameType === eventTypes.
Read more >
Check if an array of objects contains a certain key-value in ...
The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true...
Read more >
How to check if array includes a value in JavaScript?
Code Recipe to check if an array includes a value in JavaScript using ES6. ... operator to loop over an object to check...
Read more >
How to check if an array includes an object in JavaScript
Using includes() Method: If array contains an object/element can be determined by using includes() method. This method returns true if the array ......
Read more >
Check if Array Contains an Object in JavaScript | bobbyhadz
Check if each object contains a property with the specified value. `Array.some()` will return `true` if the object is contained in the array....
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