Configuring Jest·续6
Sometimes it happens (especially in React Native or TypeScript projects) that 3rd party modules are published as untranspiled. Since all files inside node_modules are not transformed by default, Jest will not understand the code in these modules, resulting in syntax errors. To overcome this, you may use transformIgnorePatterns to allow transpiling such modules. You’ll find a good example of this use case in React Native Guide.
unmockedModulePathPatterns [array<string>]
Default: []
An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them. If a module’s path matches any of the patterns in this list, it will not be automatically mocked by the module loader.
This is useful for some commonly used ‘utility’ modules that are almost always used as implementation details almost all the time (like underscore/lo-dash, etc). It’s generally a best practice to keep this list as small as possible and always use explicit jest.mock()/jest.unmock() calls in individual tests. Explicit per-test setup is far easier for other readers of the test to reason about the environment the test will run in.
It is possible to override this setting in individual tests by explicitly calling jest.mock() at the top of the test file.
verbose [boolean]
Default: false
Indicates whether each individual test should be reported during the run. All errors will also still be shown on the bottom after execution. Note that if there is only one test file being run it will default to true.
watchPathIgnorePatterns [array<string>]
Default: []
An array of RegExp patterns that are matched against all source file paths before re-running tests in watch mode. If the file path matches any of the patterns, when it is updated, it will not trigger a re-run of tests.
These patterns match against the full path. Use the <rootDir> string token to include the path to your project’s root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: ["<rootDir>/node_modules/"].
Even if nothing is specified here, the watcher will ignore changes to any hidden files and directories, i.e. files and folders that begin with a dot (.).
watchPlugins [array<string | [string, Object]>]
Default: []
This option allows you to use custom watch plugins. Read more about watch plugins here.
Examples of watch plugins include:
-
jest-watch-master
-
jest-watch-select-projects
-
jest-watch-suspend
-
jest-watch-typeahead
-
jest-watch-yarn-workspaces
Note: The values in the watchPlugins property value can omit the jest-watch- prefix of the package name.
watchman [boolean]
Default: true
Whether to use watchman for file crawling.
// [string]
No default
This option allows comments in package.json. Include the comment text as the value of this key anywhere in package.json.
Example:
{ "name": "my-project", "jest": { "//": "Comment goes here", "verbose": true }}
