How can I test part of object using Jest? How can I test part of object using Jest? javascript javascript

How can I test part of object using Jest?


To check if expected object is a subset of the received object you need to use toMatchObject(object) method:

expect(parseTime('12:54')).toMatchObject({ hours: 12, minutes: 54})

or expect.objectContaining(object) matcher:

expect(parseTime('12:54')).toEqual(expect.objectContaining({ hours: 12, minutes: 54}))

they works in slightly different ways, please take a look at What's the difference between '.toMatchObject' and 'objectContaining' for details.

toContain() is designed to check that an item is in an array.