diff --git a/docs/CLI.md b/docs/CLI.md index 2c74feb3138e..4d9af6aceb25 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -138,6 +138,10 @@ When this option is provided, Jest will assume it is running in a CI environment Deletes the Jest cache directory and then exits without running tests. Will delete `cacheDirectory` if the option is passed, or Jest's default cache directory. The default cache directory can be found by calling `jest --showConfig`. _Note: clearing the cache will reduce performance._ +### `--clearMocks` + +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. + ### `--collectCoverageFrom=` A glob pattern relative to `rootDir` matching the files that coverage info needs to be collected from. @@ -272,6 +276,14 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--resetMocks` + +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. + +### `--restoreMocks` + +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. + ### `--roots` A list of paths to directories that Jest should use to search for files in. diff --git a/docs/Configuration.md b/docs/Configuration.md index a231e2db8f63..60ee6f4c889f 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -146,7 +146,7 @@ Jest attempts to scan your dependency tree once (up-front) and cache it in order Default: `false` -Automatically clear mock calls and instances before every test. Equivalent to calling `jest.clearAllMocks()` before each test. This does not remove any mock implementation that may have been provided. +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. ### `collectCoverage` \[boolean] @@ -764,7 +764,7 @@ For the full list of methods and argument types see `Reporter` interface in [pac Default: `false` -Automatically reset mock state before every test. Equivalent to calling `jest.resetAllMocks()` before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. ### `resetModules` \[boolean] @@ -849,7 +849,7 @@ While Jest does not support [package `exports`](https://nodejs.org/api/packages. Default: `false` -Automatically restore mock state before every test. Equivalent to calling `jest.restoreAllMocks()` before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. ### `rootDir` \[string] diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index aec58045feea..859adfc21361 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -81,9 +81,11 @@ mockFn.mock.instances[1] === b; // true ### `mockFn.mockClear()` -Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. +Clears all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. -Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. +Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. + +The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically before each tests. ### `mockFn.mockReset()` @@ -91,6 +93,8 @@ Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also rem This is useful when you want to completely reset a _mock_ back to its initial state. (Note that resetting a _spy_ will result in a function with no return value). +The [`mockReset`](configuration#resetmocks-boolean) configuration option is available to reset mocks automatically before each test. + ### `mockFn.mockRestore()` Does everything that [`mockFn.mockReset()`](#mockfnmockreset) does, and also restores the original (non-mocked) implementation. @@ -99,7 +103,7 @@ This is useful when you want to mock functions in certain test cases and restore Beware that `mockFn.mockRestore` only works when the mock was created with `jest.spyOn`. Thus you have to take care of restoration yourself when manually assigning `jest.fn()`. -The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. +The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically before each test. ### `mockFn.mockImplementation(fn)` diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 85f78feedfa6..eb5dabb2b170 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -148,8 +148,8 @@ export const options = { }, clearMocks: { description: - 'Automatically clear mock calls and instances between every ' + - 'test. Equivalent to calling jest.clearAllMocks() between each test.', + 'Automatically clear mock calls, instances and results before every test. ' + + 'Equivalent to calling jest.clearAllMocks() before each test.', type: 'boolean', }, collectCoverage: { @@ -440,8 +440,8 @@ export const options = { }, resetMocks: { description: - 'Automatically reset mock state between every test. ' + - 'Equivalent to calling jest.resetAllMocks() between each test.', + 'Automatically reset mock state before every test. ' + + 'Equivalent to calling jest.resetAllMocks() before each test.', type: 'boolean', }, resetModules: { @@ -456,8 +456,8 @@ export const options = { }, restoreMocks: { description: - 'Automatically restore mock state and implementation between every test. ' + - 'Equivalent to calling jest.restoreAllMocks() between each test.', + 'Automatically restore mock state and implementation before every test. ' + + 'Equivalent to calling jest.restoreAllMocks() before each test.', type: 'boolean', }, rootDir: { diff --git a/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap b/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap index 7db61a7b69cf..05fb989e8bc1 100644 --- a/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap +++ b/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap @@ -108,7 +108,7 @@ Array [ }, Object { "initial": false, - "message": "Automatically clear mock calls and instances between every test?", + "message": "Automatically clear mock calls, instances and results before every test?", "name": "clearMocks", "type": "confirm", }, @@ -131,7 +131,7 @@ module.exports = { // The directory where Jest should store its cached dependency information // cacheDirectory: \\"/tmp/jest\\", - // Automatically clear mock calls and instances between every test + // Automatically clear mock calls, instances and results before every test // clearMocks: false, // Indicates whether the coverage information should be collected while executing the test @@ -219,7 +219,7 @@ module.exports = { // Use this configuration option to add custom reporters to Jest // reporters: undefined, - // Automatically reset mock state between every test + // Automatically reset mock state before every test // resetMocks: false, // Reset the module registry before running each individual test @@ -228,7 +228,7 @@ module.exports = { // A path to a custom resolver // resolver: undefined, - // Automatically restore mock state between every test + // Automatically restore mock state and implementation before every test // restoreMocks: false, // The root directory that Jest should scan for tests and modules within diff --git a/packages/jest-cli/src/init/questions.ts b/packages/jest-cli/src/init/questions.ts index 235411dc441a..fd4e9325ff7f 100644 --- a/packages/jest-cli/src/init/questions.ts +++ b/packages/jest-cli/src/init/questions.ts @@ -42,7 +42,8 @@ const defaultQuestions: Array = [ }, { initial: false, - message: 'Automatically clear mock calls and instances between every test?', + message: + 'Automatically clear mock calls, instances and results before every test?', name: 'clearMocks', type: 'confirm', }, diff --git a/packages/jest-config/src/Descriptions.ts b/packages/jest-config/src/Descriptions.ts index 07d170eb9c44..686146c4ced3 100644 --- a/packages/jest-config/src/Descriptions.ts +++ b/packages/jest-config/src/Descriptions.ts @@ -12,7 +12,8 @@ const descriptions: {[key in keyof Config.InitialOptions]: string} = { bail: 'Stop running tests after `n` failures', cacheDirectory: 'The directory where Jest should store its cached dependency information', - clearMocks: 'Automatically clear mock calls and instances between every test', + clearMocks: + 'Automatically clear mock calls, instances and results before every test', collectCoverage: 'Indicates whether the coverage information should be collected while executing the test', collectCoverageFrom: @@ -53,10 +54,11 @@ const descriptions: {[key in keyof Config.InitialOptions]: string} = { preset: "A preset that is used as a base for Jest's configuration", projects: 'Run tests from one or more projects', reporters: 'Use this configuration option to add custom reporters to Jest', - resetMocks: 'Automatically reset mock state between every test', + resetMocks: 'Automatically reset mock state before every test', resetModules: 'Reset the module registry before running each individual test', resolver: 'A path to a custom resolver', - restoreMocks: 'Automatically restore mock state between every test', + restoreMocks: + 'Automatically restore mock state and implementation before every test', rootDir: 'The root directory that Jest should scan for tests and modules within', roots: diff --git a/website/versioned_docs/version-25.x/CLI.md b/website/versioned_docs/version-25.x/CLI.md index b4ced67f6e51..a6f3443d2017 100644 --- a/website/versioned_docs/version-25.x/CLI.md +++ b/website/versioned_docs/version-25.x/CLI.md @@ -138,6 +138,10 @@ When this option is provided, Jest will assume it is running in a CI environment Deletes the Jest cache directory and then exits without running tests. Will delete `cacheDirectory` if the option is passed, or Jest's default cache directory. The default cache directory can be found by calling `jest --showConfig`. _Note: clearing the cache will reduce performance._ +### `--clearMocks` + +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. + ### `--collectCoverageFrom=` A glob pattern relative to `rootDir` matching the files that coverage info needs to be collected from. @@ -260,6 +264,14 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--resetMocks` + +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. + +### `--restoreMocks` + +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. + ### `--roots` A list of paths to directories that Jest should use to search for files in. diff --git a/website/versioned_docs/version-25.x/Configuration.md b/website/versioned_docs/version-25.x/Configuration.md index 28edb5f87683..f00bcb705ddd 100644 --- a/website/versioned_docs/version-25.x/Configuration.md +++ b/website/versioned_docs/version-25.x/Configuration.md @@ -125,7 +125,7 @@ Jest attempts to scan your dependency tree once (up-front) and cache it in order Default: `false` -Automatically clear mock calls and instances before every test. Equivalent to calling `jest.clearAllMocks()` before each test. This does not remove any mock implementation that may have been provided. +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. ### `collectCoverage` \[boolean] @@ -702,7 +702,7 @@ For the full list of methods and argument types see `Reporter` interface in [pac Default: `false` -Automatically reset mock state before every test. Equivalent to calling `jest.resetAllMocks()` before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. ### `resetModules` \[boolean] @@ -736,7 +736,7 @@ Note: the defaultResolver passed as an option is the Jest default resolver which Default: `false` -Automatically restore mock state before every test. Equivalent to calling `jest.restoreAllMocks()` before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. ### `rootDir` \[string] diff --git a/website/versioned_docs/version-25.x/MockFunctionAPI.md b/website/versioned_docs/version-25.x/MockFunctionAPI.md index aec58045feea..859adfc21361 100644 --- a/website/versioned_docs/version-25.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-25.x/MockFunctionAPI.md @@ -81,9 +81,11 @@ mockFn.mock.instances[1] === b; // true ### `mockFn.mockClear()` -Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. +Clears all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. -Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. +Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. + +The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically before each tests. ### `mockFn.mockReset()` @@ -91,6 +93,8 @@ Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also rem This is useful when you want to completely reset a _mock_ back to its initial state. (Note that resetting a _spy_ will result in a function with no return value). +The [`mockReset`](configuration#resetmocks-boolean) configuration option is available to reset mocks automatically before each test. + ### `mockFn.mockRestore()` Does everything that [`mockFn.mockReset()`](#mockfnmockreset) does, and also restores the original (non-mocked) implementation. @@ -99,7 +103,7 @@ This is useful when you want to mock functions in certain test cases and restore Beware that `mockFn.mockRestore` only works when the mock was created with `jest.spyOn`. Thus you have to take care of restoration yourself when manually assigning `jest.fn()`. -The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. +The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically before each test. ### `mockFn.mockImplementation(fn)` diff --git a/website/versioned_docs/version-26.x/CLI.md b/website/versioned_docs/version-26.x/CLI.md index a5ce142b62d1..ea113388ed19 100644 --- a/website/versioned_docs/version-26.x/CLI.md +++ b/website/versioned_docs/version-26.x/CLI.md @@ -138,6 +138,10 @@ When this option is provided, Jest will assume it is running in a CI environment Deletes the Jest cache directory and then exits without running tests. Will delete `cacheDirectory` if the option is passed, or Jest's default cache directory. The default cache directory can be found by calling `jest --showConfig`. _Note: clearing the cache will reduce performance._ +### `--clearMocks` + +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. + ### `--collectCoverageFrom=` A glob pattern relative to `rootDir` matching the files that coverage info needs to be collected from. @@ -272,6 +276,14 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--resetMocks` + +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. + +### `--restoreMocks` + +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. + ### `--roots` A list of paths to directories that Jest should use to search for files in. diff --git a/website/versioned_docs/version-26.x/Configuration.md b/website/versioned_docs/version-26.x/Configuration.md index ca92002f1dbe..0d8af958caa5 100644 --- a/website/versioned_docs/version-26.x/Configuration.md +++ b/website/versioned_docs/version-26.x/Configuration.md @@ -146,7 +146,7 @@ Jest attempts to scan your dependency tree once (up-front) and cache it in order Default: `false` -Automatically clear mock calls and instances before every test. Equivalent to calling `jest.clearAllMocks()` before each test. This does not remove any mock implementation that may have been provided. +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. ### `collectCoverage` \[boolean] @@ -737,7 +737,7 @@ For the full list of methods and argument types see `Reporter` interface in [pac Default: `false` -Automatically reset mock state before every test. Equivalent to calling `jest.resetAllMocks()` before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. ### `resetModules` \[boolean] @@ -818,7 +818,7 @@ module.exports = (request, options) => { Default: `false` -Automatically restore mock state before every test. Equivalent to calling `jest.restoreAllMocks()` before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. ### `rootDir` \[string] diff --git a/website/versioned_docs/version-26.x/MockFunctionAPI.md b/website/versioned_docs/version-26.x/MockFunctionAPI.md index aec58045feea..859adfc21361 100644 --- a/website/versioned_docs/version-26.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-26.x/MockFunctionAPI.md @@ -81,9 +81,11 @@ mockFn.mock.instances[1] === b; // true ### `mockFn.mockClear()` -Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. +Clears all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. -Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. +Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. + +The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically before each tests. ### `mockFn.mockReset()` @@ -91,6 +93,8 @@ Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also rem This is useful when you want to completely reset a _mock_ back to its initial state. (Note that resetting a _spy_ will result in a function with no return value). +The [`mockReset`](configuration#resetmocks-boolean) configuration option is available to reset mocks automatically before each test. + ### `mockFn.mockRestore()` Does everything that [`mockFn.mockReset()`](#mockfnmockreset) does, and also restores the original (non-mocked) implementation. @@ -99,7 +103,7 @@ This is useful when you want to mock functions in certain test cases and restore Beware that `mockFn.mockRestore` only works when the mock was created with `jest.spyOn`. Thus you have to take care of restoration yourself when manually assigning `jest.fn()`. -The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. +The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically before each test. ### `mockFn.mockImplementation(fn)` diff --git a/website/versioned_docs/version-27.0/CLI.md b/website/versioned_docs/version-27.0/CLI.md index f54a685d3250..58d2a91f09d3 100644 --- a/website/versioned_docs/version-27.0/CLI.md +++ b/website/versioned_docs/version-27.0/CLI.md @@ -138,6 +138,10 @@ When this option is provided, Jest will assume it is running in a CI environment Deletes the Jest cache directory and then exits without running tests. Will delete `cacheDirectory` if the option is passed, or Jest's default cache directory. The default cache directory can be found by calling `jest --showConfig`. _Note: clearing the cache will reduce performance._ +### `--clearMocks` + +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. + ### `--collectCoverageFrom=` A glob pattern relative to `rootDir` matching the files that coverage info needs to be collected from. @@ -272,6 +276,14 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--resetMocks` + +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. + +### `--restoreMocks` + +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. + ### `--roots` A list of paths to directories that Jest should use to search for files in. diff --git a/website/versioned_docs/version-27.0/Configuration.md b/website/versioned_docs/version-27.0/Configuration.md index bb0ade1beab2..321b7e74d129 100644 --- a/website/versioned_docs/version-27.0/Configuration.md +++ b/website/versioned_docs/version-27.0/Configuration.md @@ -146,7 +146,7 @@ Jest attempts to scan your dependency tree once (up-front) and cache it in order Default: `false` -Automatically clear mock calls and instances before every test. Equivalent to calling `jest.clearAllMocks()` before each test. This does not remove any mock implementation that may have been provided. +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. ### `collectCoverage` \[boolean] @@ -764,7 +764,7 @@ For the full list of methods and argument types see `Reporter` interface in [pac Default: `false` -Automatically reset mock state before every test. Equivalent to calling `jest.resetAllMocks()` before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. ### `resetModules` \[boolean] @@ -845,7 +845,7 @@ module.exports = (request, options) => { Default: `false` -Automatically restore mock state before every test. Equivalent to calling `jest.restoreAllMocks()` before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. ### `rootDir` \[string] diff --git a/website/versioned_docs/version-27.0/MockFunctionAPI.md b/website/versioned_docs/version-27.0/MockFunctionAPI.md index aec58045feea..859adfc21361 100644 --- a/website/versioned_docs/version-27.0/MockFunctionAPI.md +++ b/website/versioned_docs/version-27.0/MockFunctionAPI.md @@ -81,9 +81,11 @@ mockFn.mock.instances[1] === b; // true ### `mockFn.mockClear()` -Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. +Clears all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. -Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. +Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. + +The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically before each tests. ### `mockFn.mockReset()` @@ -91,6 +93,8 @@ Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also rem This is useful when you want to completely reset a _mock_ back to its initial state. (Note that resetting a _spy_ will result in a function with no return value). +The [`mockReset`](configuration#resetmocks-boolean) configuration option is available to reset mocks automatically before each test. + ### `mockFn.mockRestore()` Does everything that [`mockFn.mockReset()`](#mockfnmockreset) does, and also restores the original (non-mocked) implementation. @@ -99,7 +103,7 @@ This is useful when you want to mock functions in certain test cases and restore Beware that `mockFn.mockRestore` only works when the mock was created with `jest.spyOn`. Thus you have to take care of restoration yourself when manually assigning `jest.fn()`. -The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. +The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically before each test. ### `mockFn.mockImplementation(fn)` diff --git a/website/versioned_docs/version-27.1/CLI.md b/website/versioned_docs/version-27.1/CLI.md index f54a685d3250..58d2a91f09d3 100644 --- a/website/versioned_docs/version-27.1/CLI.md +++ b/website/versioned_docs/version-27.1/CLI.md @@ -138,6 +138,10 @@ When this option is provided, Jest will assume it is running in a CI environment Deletes the Jest cache directory and then exits without running tests. Will delete `cacheDirectory` if the option is passed, or Jest's default cache directory. The default cache directory can be found by calling `jest --showConfig`. _Note: clearing the cache will reduce performance._ +### `--clearMocks` + +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. + ### `--collectCoverageFrom=` A glob pattern relative to `rootDir` matching the files that coverage info needs to be collected from. @@ -272,6 +276,14 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--resetMocks` + +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. + +### `--restoreMocks` + +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. + ### `--roots` A list of paths to directories that Jest should use to search for files in. diff --git a/website/versioned_docs/version-27.1/Configuration.md b/website/versioned_docs/version-27.1/Configuration.md index d10bfd7070a3..a5d110e3b1fc 100644 --- a/website/versioned_docs/version-27.1/Configuration.md +++ b/website/versioned_docs/version-27.1/Configuration.md @@ -146,7 +146,7 @@ Jest attempts to scan your dependency tree once (up-front) and cache it in order Default: `false` -Automatically clear mock calls and instances before every test. Equivalent to calling `jest.clearAllMocks()` before each test. This does not remove any mock implementation that may have been provided. +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. ### `collectCoverage` \[boolean] @@ -764,7 +764,7 @@ For the full list of methods and argument types see `Reporter` interface in [pac Default: `false` -Automatically reset mock state before every test. Equivalent to calling `jest.resetAllMocks()` before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. ### `resetModules` \[boolean] @@ -845,7 +845,7 @@ module.exports = (request, options) => { Default: `false` -Automatically restore mock state before every test. Equivalent to calling `jest.restoreAllMocks()` before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. ### `rootDir` \[string] diff --git a/website/versioned_docs/version-27.1/MockFunctionAPI.md b/website/versioned_docs/version-27.1/MockFunctionAPI.md index aec58045feea..859adfc21361 100644 --- a/website/versioned_docs/version-27.1/MockFunctionAPI.md +++ b/website/versioned_docs/version-27.1/MockFunctionAPI.md @@ -81,9 +81,11 @@ mockFn.mock.instances[1] === b; // true ### `mockFn.mockClear()` -Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. +Clears all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. -Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. +Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. + +The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically before each tests. ### `mockFn.mockReset()` @@ -91,6 +93,8 @@ Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also rem This is useful when you want to completely reset a _mock_ back to its initial state. (Note that resetting a _spy_ will result in a function with no return value). +The [`mockReset`](configuration#resetmocks-boolean) configuration option is available to reset mocks automatically before each test. + ### `mockFn.mockRestore()` Does everything that [`mockFn.mockReset()`](#mockfnmockreset) does, and also restores the original (non-mocked) implementation. @@ -99,7 +103,7 @@ This is useful when you want to mock functions in certain test cases and restore Beware that `mockFn.mockRestore` only works when the mock was created with `jest.spyOn`. Thus you have to take care of restoration yourself when manually assigning `jest.fn()`. -The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. +The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically before each test. ### `mockFn.mockImplementation(fn)` diff --git a/website/versioned_docs/version-27.2/CLI.md b/website/versioned_docs/version-27.2/CLI.md index 4ef5661b28d3..24c0f5993bdb 100644 --- a/website/versioned_docs/version-27.2/CLI.md +++ b/website/versioned_docs/version-27.2/CLI.md @@ -138,6 +138,10 @@ When this option is provided, Jest will assume it is running in a CI environment Deletes the Jest cache directory and then exits without running tests. Will delete `cacheDirectory` if the option is passed, or Jest's default cache directory. The default cache directory can be found by calling `jest --showConfig`. _Note: clearing the cache will reduce performance._ +### `--clearMocks` + +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. + ### `--collectCoverageFrom=` A glob pattern relative to `rootDir` matching the files that coverage info needs to be collected from. @@ -272,6 +276,14 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--resetMocks` + +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. + +### `--restoreMocks` + +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. + ### `--roots` A list of paths to directories that Jest should use to search for files in. diff --git a/website/versioned_docs/version-27.2/Configuration.md b/website/versioned_docs/version-27.2/Configuration.md index e0719080079a..95aa2affc193 100644 --- a/website/versioned_docs/version-27.2/Configuration.md +++ b/website/versioned_docs/version-27.2/Configuration.md @@ -146,7 +146,7 @@ Jest attempts to scan your dependency tree once (up-front) and cache it in order Default: `false` -Automatically clear mock calls and instances before every test. Equivalent to calling `jest.clearAllMocks()` before each test. This does not remove any mock implementation that may have been provided. +Automatically clear mock calls, instances and results before every test. Equivalent to calling [`jest.clearAllMocks()`](JestObjectAPI.md#jestclearallmocks) before each test. This does not remove any mock implementation that may have been provided. ### `collectCoverage` \[boolean] @@ -764,7 +764,7 @@ For the full list of methods and argument types see `Reporter` interface in [pac Default: `false` -Automatically reset mock state before every test. Equivalent to calling `jest.resetAllMocks()` before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. +Automatically reset mock state before every test. Equivalent to calling [`jest.resetAllMocks()`](JestObjectAPI.md#jestresetallmocks) before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. ### `resetModules` \[boolean] @@ -849,7 +849,7 @@ While Jest does not support [package `exports`](https://nodejs.org/api/packages. Default: `false` -Automatically restore mock state before every test. Equivalent to calling `jest.restoreAllMocks()` before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. +Automatically restore mock state and implementation before every test. Equivalent to calling [`jest.restoreAllMocks()`](JestObjectAPI.md#jestrestoreallmocks) before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. ### `rootDir` \[string] diff --git a/website/versioned_docs/version-27.2/MockFunctionAPI.md b/website/versioned_docs/version-27.2/MockFunctionAPI.md index aec58045feea..859adfc21361 100644 --- a/website/versioned_docs/version-27.2/MockFunctionAPI.md +++ b/website/versioned_docs/version-27.2/MockFunctionAPI.md @@ -81,9 +81,11 @@ mockFn.mock.instances[1] === b; // true ### `mockFn.mockClear()` -Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. +Clears all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions. -Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. +Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. + +The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically before each tests. ### `mockFn.mockReset()` @@ -91,6 +93,8 @@ Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also rem This is useful when you want to completely reset a _mock_ back to its initial state. (Note that resetting a _spy_ will result in a function with no return value). +The [`mockReset`](configuration#resetmocks-boolean) configuration option is available to reset mocks automatically before each test. + ### `mockFn.mockRestore()` Does everything that [`mockFn.mockReset()`](#mockfnmockreset) does, and also restores the original (non-mocked) implementation. @@ -99,7 +103,7 @@ This is useful when you want to mock functions in certain test cases and restore Beware that `mockFn.mockRestore` only works when the mock was created with `jest.spyOn`. Thus you have to take care of restoration yourself when manually assigning `jest.fn()`. -The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. +The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically before each test. ### `mockFn.mockImplementation(fn)`