Sometimes, we want to test part of object using Jest and JavaScript.
In this article, we’ll look at how to test part of object using Jest and JavaScript.
How to test part of object using Jest and JavaScript?
To test part of object using Jest and JavaScript, we can use the toMatchObject method.
For instance, we write
expect(parseTime("12:54")).toMatchObject({ hours: 12, minutes: 54 });
to call toMatchObject to check that the object returned by parseTime("12:54") has { hours: 12, minutes: 54 } in it.
Conclusion
To test part of object using Jest and JavaScript, we can use the toMatchObject method.