This tutorial could not be loaded.
Loading tutorial...
Interactive tutorial
Learn to write and run JavaScript unit tests with Jest on your own computer. Choose appropriate matchers for values, objects, collections, and errors; create fresh test fixtures; and use setup and teardown hooks without introducing dependencies between tests. Finish by repairing and running a small shopping-cart test suite.
Step 1 of 8
6 min
Run Your First Jest Test
Create a local Jest project, run an empty-cart test, and interpret an intentional failure.
Step 2 of 8
4 min
Match Primitive Values Precisely
Choose precise Jest assertions for primitive values, truthiness, negation, and approximate numbers.
Step 3 of 8
4 min
Compare Objects and Collections
Choose assertions that distinguish object identity from contents and check the intended aspect of a collection.
Step 4 of 8
4 min
Test Expected Errors
Test a rejected cart item by letting Jest catch the error and checking that the cart remains unchanged.
Step 5 of 8
5 min
Start Each Test with Fresh Data
Give each test an independent cart fixture and check that test order no longer matters.
Step 6 of 8
5 min
Restore Shared State with Teardown
Control a temporary currency setting and restore the original environment state after each test.
Step 7 of 8
5 min
Choose the Right Hook Scope
Choose hook scopes for a fresh cart fixture and a shared currency baseline, then trace the lifecycle around two tests.
Step 8 of 8
6 min
Repair and Run an Independent Test Suite
Repair a shopping-cart suite, run it in two test orders, and explain how its fixtures and cleanup prevent state leakage.
Video Courses
Advanced
recommended
recommended
Ideal for beginners
Thousands of online courses in video, ebooks and audiobooks.
To test your knowledge during online courses
Generated directly from your cell phone's photo gallery and sent to your email
Download our app via QR Code or the links below:.
+ 10 million
students
Free and Valid
Certificate
60 thousand free
exercises
4.8/5 rating in
app stores
Free courses in
video and ebooks