jest.config.ts
jest.config.ts - Overview
- Overview
This file configures Jest, a JavaScript testing framework, for a TypeScript project. It specifies various settings such as coverage reporting, module resolution, transformations, and test environment.
- Detailed Documentation
The file exports a configuration object for Jest.
- Purpose: Defines the Jest configuration.
- Returns: A
Config.InitialOptions
object that configures Jest.
config
object
-
Purpose: This object holds all the configuration options for Jest.
clearMocks
:- Purpose: Automatically clear mock calls, instances and results before every test.
- Type:
boolean
- Returns:
void
coverageDirectory
:- Purpose: The directory where Jest should output its coverage files.
- Type:
string
- Returns:
void
coverageReporters
:- Purpose: A list of reporter names that Jest uses when writing coverage results.
- Type:
string[]
- Returns:
void
collectCoverageFrom
:- Purpose: An array of glob patterns indicating a set of files for which coverage information should be collected.
- Type:
string[]
- Returns:
void
moduleFileExtensions
:- Purpose: An array of file extensions that Jest should treat as modules.
- Type:
string[]
- Returns:
void
modulePathIgnorePatterns
:- Purpose: An array of regex patterns that Jest uses to detect module paths to ignore.
- Type:
string[]
- Returns:
void
moduleNameMapper
:- Purpose: An object mapping module names to alternative module paths. Used for mocking CSS and MD files.
- Type:
{ [key: string]: string }
- Returns:
void
globals
:- Purpose: An object of global variables that will be available in the testing environment. Configures
ts-jest
to use ESM. - Type:
{ [key: string]: any }
- Returns:
void
- Purpose: An object of global variables that will be available in the testing environment. Configures
testMatch
:- Purpose: An array of glob patterns Jest uses to find test files.
- Type:
string[]
- Returns:
void
preset
:- Purpose: A string that points to a Jest preset.
- Type:
string
- Returns:
void
transform
:- Purpose: An object to define transformers.
- Type:
{ [key: string]: string }
- Returns:
void
transformIgnorePatterns
:- Purpose: An array of regex patterns that Jest uses to detect files to transform.
- Type:
string[]
- Returns:
void
setupFilesAfterEnv
:- Purpose: An array of module paths that will be run some code to configure or set up the testing environment before each test.
- Type:
string[]
- Returns:
void
testPathIgnorePatterns
:- Purpose: An array of regex patterns that Jest uses to detect test paths to ignore.
- Type:
string[]
- Returns:
void
moduleDirectories
:- Purpose: An array of directory names to be searched recursively up the tree.
- Type:
string[]
- Returns:
void
testEnvironment
:- Purpose: The test environment that will be used for testing.
- Type:
string
- Returns:
void
testEnvironmentOptions
:- Purpose: Options for the test environment.
- Type:
{ [key: string]: any }
- Returns:
void
coverageThreshold
:- Purpose: An object that specifies the thresholds for coverage metrics.
- Type:
{ [key: string]: any }
- Returns:
void
- Code Examples
None
- Clarity and Accuracy
The documentation is based on the code provided.
Include in Getting Started: NO