Jest.js

Why use Jest?

Why use Jest?

  • It's fast
  • Easy to configure
  • Snapshot testing
  • Build for testing JavaScript (Optimized for ReactJS)
  • Used by Facebook (maintainer),
    Twitter, Spotify, AirBnB,
    New York Times, Instagram

Jest built-in features

Jest built-in features

  • Mocking
  • Snapshotting
  • Typescript support
  • Coverage report

Jest methods

describe()

With describe, you define a test suite that can contain 1 or more tests.

test() or it()

With test or it method, you define a test.

expect()

With the expect method is a matcher which returns the output to the next method. For example toBe()

Check other matcher methods: https://jestjs.io/docs/en/expect

Jest mocking

What is mocking?

The goal for mocking is to replace something we don’t control with something we do, so it’s important that what we replace it with has all the features we need.

When to use mocking?

The goal for mocking is to replace something we don’t control with something we do, so it’s important that what we replace it with has all the features we need.

Jest.js

By CodePamoja

Jest.js

  • 16