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

briwa on May 26, 2019

Jest has always been my go-to unit testing tool. It is so robust I'm starting to think that I've always been underutilizing it. Although the tests ... [Read Full]
markdown guide
 

Here's an extra one I love to use:

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

expect(anyObject).toEqual(expect.objectContaining({ foo: "bar" }))

expect.objectContaining docs.

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

 

👏 Bravo for sharing the ability to iterate over test cases. I’ve been looking for something like that for a long time. I’ve hand rolled it myself in jest, Xunit, Nunit, mocha, jasmine, etc. I can’t wait to try this out on Tuesday when I go back to work. Thank you! :)

 

Majestic looks cool! I like to launch Jest from vs code using ‘—watch’, so it’s running while changing key parts of my components.

Another cool way of using jest is when using the storybook plugin for Structural Testing in React.

 
code of conduct - report abuse