How to do jest testing on array.every method in javascript

Majumder, Mousumi 0 Reputation points
2023-08-04T07:24:21.0266667+00:00

I am developing a project in react js .I am new to this field. But I stuck in jest testing .I developed this :-

I have one array (breeds).

const breeds =

{ breeds

[ {id : 1,

model: cern ,

dogs: name1: 'peter', name2:'jetsky', name3:'robin',}

]}

I have an object (Dogs).

const Dogs = object.freeze({ name1 : 'peter', name2 : 'jetsky', })

I changed it to array like this

const dogsname =object.values(Dogs);

Then I need to compare this array of subset present of main array or not :

So for this I did this

const value = breeds.every(val=> dogsname.includes(val).

So I am able to get the data that it is subset of main array.

Now I am doing unit testing on this with jest framework.But not able to get this. I did this :

test ('render the element which is present in array',()=>{

const dogsname = object.values(Dogs);

const breedname = breeds.dogs; expect(breedname).toEqual(expect.arrayContaining(dogsname)); })

But its showing error received: undefined, not able to do that testing .Thanks!

Microsoft 365 and Office Development Office JavaScript API
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.