Categories
JavaScript Answers

How to test part of object using Jest and JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.