Today I Learned

hashrocket A Hashrocket project

Jest Expect Object Containing

I used to do this a lot:

const { somethingIDontCareAbout, ...everthingIDoCareAbout } = stuff
expect(everythingIDoCareAbout).toEqual(expectedStuff)

Now I learned about objectContaining and I can do this instead:

expect(stuff).toEqual(expect.objectContaining(expectedStuff))

H/T Dillon Hafer

See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.