Gambit2007
Gambit2007

Reputation: 3978

sinon - how to check if a value is in an array?

I know that i can check a specific value in a specific index, for example - to check for the value at index 0:

sinon.assert.match(myArr[0], someValue)

But how do i check if someValue is anywhere in myArr?

Upvotes: 0

Views: 842

Answers (1)

DenverCoder1
DenverCoder1

Reputation: 2501

Here is one way you could do it if you don't want to create a loop that iterates through each element.

 myArr.includes(someValue);

I haven't tried it with sinon, but see if this works:

assert.equals(myArr.includes(someValue), true);
// or
assert(myArr.includes(someValue));

Upvotes: 1

Related Questions