jest
Run JavaScript and TypeScript tests
TLDR
Run all available tests
Run the test suites from the given files
Run the test suites from files within the current and subdirectories, whose paths match the given regex
Run the tests whose names match the given regex
Run test suites related to a given source file
Run test suites related to all uncommitted files
Watch files for changes and automatically re-run related tests
Display help
SYNOPSIS
jest [options] [patterns]
jest --version
jest --help
PARAMETERS
--coverage
Collects code coverage information from your project.
--watch
Enters a "watch mode," rerunning tests when source files change.
--watchAll
Similar to --watch, but watches all files, even if not in a Git repo.
--config
Specifies the path to a Jest configuration file.
--testPathPattern
Runs tests whose file paths match the provided regular expression.
--runInBand
Executes all tests serially in the current process, useful for debugging.
--clearCache
Deletes the Jest cache directory, useful for resolving cache-related issues.
--forceExit
Forces Jest to exit after test runs complete, even if there are open handles.
--verbose
Displays individual test results and the full test suite hierarchy.
--silent
Prevents tests from printing messages to the console during execution.
--version
Prints the installed Jest version and exits.
--help
Displays all available CLI options for Jest.
DESCRIPTION
Jest is a widely-adopted JavaScript testing framework developed by Facebook (now Meta) for testing JavaScript and TypeScript codebases. It provides a comprehensive solution for unit, integration, and snapshot testing. Key features include its "zero-config" setup, offering a smooth onboarding experience, alongside exceptional performance through parallel test execution. Jest boasts an integrated assertion library, powerful mocking capabilities for isolating code, and built-in code coverage reporting, simplifying the development workflow. It is commonly utilized in diverse JavaScript environments, including React, Angular, Vue.js, and Node.js applications, significantly contributing to code quality, reliability, and maintainability across projects. Its focus on developer experience makes it a popular choice for modern web development.
CAVEATS
Jest requires Node.js and a package manager like npm or yarn to be installed on your system. It can be resource-intensive for very large test suites, and advanced configurations might require a deeper understanding of its ecosystem. While Jest is versatile, its primary focus remains the JavaScript/TypeScript environment.
SNAPSHOT TESTING
Jest's unique snapshot testing feature is used to test large objects or UI components by comparing a serialized representation (a snapshot) against a previously stored version. This quickly identifies unintended changes to the UI or data structure.
MOCKING
Jest provides powerful mocking capabilities for functions, modules, and timers. This allows developers to isolate the code under test from its dependencies, controlling their behavior and ensuring consistent test results without side effects.
JSDOM
While Jest tests typically run in a Node.js environment, for front-end components that rely on browser APIs, Jest uses JSDOM. JSDOM is a pure JavaScript implementation of web standards, allowing Jest to simulate a browser environment without requiring a real browser.
HISTORY
Jest was developed by Facebook (now Meta) and open-sourced around 2014-2015, initially to test React components. Its innovative features, such as snapshot testing, and a focus on developer experience quickly propelled its adoption. It rapidly became a leading testing framework in the JavaScript ecosystem, continuing to be actively maintained and evolved by Meta and the open-source community.