Skip to content
BENIBIX Learn

Jest

Development🧪 Testing & QualityTest Frameworks

Also known as Jest JS, jest testing

A test tool for JavaScript. It finds your tests and runs them.

Think of it like

Think of it like a full test kit in one box. Everything you need is inside.

Example

Emma adds Jest to her React app. She types npx jest, and it runs her 85 tests in 6 seconds.

Why it matters

It works with almost no set-up. A JavaScript project can have tests from day one.

Definition

Jest is a popular tool for testing JavaScript and TypeScript code. Facebook built it and released it in 2014. It finds test files, runs them and shows which passed. It also has mocks, spies and snapshot tests built in, so most projects need nothing extra. Test files usually end in .test.js, and checks are written with expect.

Example code

console
$ npx jest
Tests:       1 passed, 1 total
Jest found the tests, ran them and printed the count.

Common mistake

Testing code that needs a browser in Jest's default setup. Pick a browser-like test environment first.

Key takeaways

  1. 1
    For JavaScript. And TypeScript.
  2. 2
    All in one. Runner, mocks, snapshots.
  3. 3
    Little set-up. Works out of the box.

Compare