DEV Community

loading...

Discussion on: My "Whoa, I didn't know that!" moments with Jest

Collapse
wes profile image
Wes Souza

Here's an extra one I love to use:

const anyObject = {
  complex: true,
  otherProperties: "yes",
  foo: "bar",
};

expect(anyObject).toEqual(expect.objectContaining({ foo: "bar" }))
Enter fullscreen mode Exit fullscreen mode

expect.objectContaining docs.

Really useful for testing objects where you only care about a small part that changes, instead of using snapshots.