Unit Testing (Jest & Vitest)
Unit tests verify isolated code modules. By utilizing assertions, setup/teardown hooks, and comparing Jest with the modern ESM-first Vitest, developers build fast, maintainable test suites.
Knowledge Check
2 questions · pass at 70%
1. What is the primary architectural difference between Jest and Vitest?
Interview Questions
1 questionsCheatsheet
Download-ready referenceDescribe Groups related tests (e.g. describe("cart module")).
Test/It Defines a single test case block.
Expect Executes assertions (toBe, toEqual, toContain).
beforeEach Setup hook executing before each test case.
beforeAll Setup hook executing once before the suite.
Basic Assertions:
expect(x).toBe(y) Referential equality (===).
expect(x).toEqual(y) Deep object/array equality check.
expect(x).toBeNull() Asserts x is null.
expect(x).toThrow() Asserts function throws an error.