The return value of jest test interface is the same as expected.

now there is a requirement that if the return value of the interface is very complex, including an array of objects, and there are a lot of properties in the object, how can you use jest to ensure that the returned properties are the same as expected?
look at the document is full of mock some simple return values, what about complex ones? I can"t check it by hand, can I?
or is this test beyond the scope of jest?

Nov.15,2021

you can use .toEqual


upstairs has been answered, toEqual recursively checks each field of the object or array.


if you want to be exactly the same, as you said upstairs, use toEqual
if you just want to verify certain attributes, you can write judgment logic in expect , return true or false , and then toBe

.
Menu