From 133b50dfd0fb137b97be9c60dc0a81d7810914fc Mon Sep 17 00:00:00 2001 From: John Undersander Date: Mon, 21 Feb 2022 12:15:15 -0600 Subject: [PATCH 1/8] docs(ES6ClassMocks): add clarity for module factory limitations - close #11862 - related to #11455 --- CHANGELOG.md | 1 + docs/Es6ClassMocks.md | 19 ++++++++++++++++++- .../version-25.x/Es6ClassMocks.md | 19 ++++++++++++++++++- .../version-26.x/Es6ClassMocks.md | 19 ++++++++++++++++++- .../version-27.0/Es6ClassMocks.md | 19 ++++++++++++++++++- .../version-27.1/Es6ClassMocks.md | 19 ++++++++++++++++++- .../version-27.2/Es6ClassMocks.md | 19 ++++++++++++++++++- .../version-27.4/Es6ClassMocks.md | 19 ++++++++++++++++++- .../version-27.5/Es6ClassMocks.md | 19 ++++++++++++++++++- 9 files changed, 145 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01f3284eb17e..c59f244cd403 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ - `[jest-transform]` Update `write-file-atomic` to v4 ([#12357](https://github.com/facebook/jest/pull/12357)) - `[jest-types]` [**BREAKING**] Remove `Config.Glob` and `Config.Path` ([#12406](https://github.com/facebook/jest/pull/12406)) - `[jest]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329)) +- `[docs, website]` Add clarity for module factory limitations ([#12453](https://github.com/facebook/jest/pull/12453)) ### Performance diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. diff --git a/website/versioned_docs/version-25.x/Es6ClassMocks.md b/website/versioned_docs/version-25.x/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/website/versioned_docs/version-25.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-25.x/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. diff --git a/website/versioned_docs/version-26.x/Es6ClassMocks.md b/website/versioned_docs/version-26.x/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/website/versioned_docs/version-26.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-26.x/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. diff --git a/website/versioned_docs/version-27.0/Es6ClassMocks.md b/website/versioned_docs/version-27.0/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/website/versioned_docs/version-27.0/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.0/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. diff --git a/website/versioned_docs/version-27.1/Es6ClassMocks.md b/website/versioned_docs/version-27.1/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/website/versioned_docs/version-27.1/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.1/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. diff --git a/website/versioned_docs/version-27.2/Es6ClassMocks.md b/website/versioned_docs/version-27.2/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/website/versioned_docs/version-27.2/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.2/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. diff --git a/website/versioned_docs/version-27.4/Es6ClassMocks.md b/website/versioned_docs/version-27.4/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/website/versioned_docs/version-27.4/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.4/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. diff --git a/website/versioned_docs/version-27.5/Es6ClassMocks.md b/website/versioned_docs/version-27.5/Es6ClassMocks.md index 3907980f80b2..f39c8a96ec38 100644 --- a/website/versioned_docs/version-27.5/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.5/Es6ClassMocks.md @@ -140,7 +140,11 @@ jest.mock('./sound-player', () => { }); ``` -A limitation with the factory parameter is that, since calls to `jest.mock()` are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. It's up to you to guarantee that they will be initialized on time! For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: + +For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. ```javascript // Note: this will fail @@ -153,6 +157,19 @@ jest.mock('./sound-player', () => { }); ``` +The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. + +```javascript +import SoundPlayer from './sound-player'; +const mockSoundPlayer = jest.fn().mockImplementation(() => { + return {playSoundFile: mockPlaySoundFile}; +}); +// results in a ReferenceError +jest.mock('./sound-player', () => { + return mockSoundPlayer; +}); +``` + ### Replacing the mock using [`mockImplementation()`](MockFunctionAPI.md#mockfnmockimplementationfn) or [`mockImplementationOnce()`](MockFunctionAPI.md#mockfnmockimplementationoncefn) You can replace all of the above mocks in order to change the implementation, for a single test or all tests, by calling `mockImplementation()` on the existing mock. From dce318986b18931c74ad9d07552342a4ac895bd7 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 08:32:20 +0100 Subject: [PATCH 2/8] Apply suggestions from code review --- docs/Es6ClassMocks.md | 4 ++-- website/versioned_docs/version-25.x/Es6ClassMocks.md | 4 ++-- website/versioned_docs/version-26.x/Es6ClassMocks.md | 4 ++-- website/versioned_docs/version-27.0/Es6ClassMocks.md | 4 ++-- website/versioned_docs/version-27.1/Es6ClassMocks.md | 4 ++-- website/versioned_docs/version-27.2/Es6ClassMocks.md | 4 ++-- website/versioned_docs/version-27.4/Es6ClassMocks.md | 4 ++-- website/versioned_docs/version-27.5/Es6ClassMocks.md | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; diff --git a/website/versioned_docs/version-25.x/Es6ClassMocks.md b/website/versioned_docs/version-25.x/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/website/versioned_docs/version-25.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-25.x/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; diff --git a/website/versioned_docs/version-26.x/Es6ClassMocks.md b/website/versioned_docs/version-26.x/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/website/versioned_docs/version-26.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-26.x/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; diff --git a/website/versioned_docs/version-27.0/Es6ClassMocks.md b/website/versioned_docs/version-27.0/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.0/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.0/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; diff --git a/website/versioned_docs/version-27.1/Es6ClassMocks.md b/website/versioned_docs/version-27.1/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.1/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.1/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; diff --git a/website/versioned_docs/version-27.2/Es6ClassMocks.md b/website/versioned_docs/version-27.2/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.2/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.2/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; diff --git a/website/versioned_docs/version-27.4/Es6ClassMocks.md b/website/versioned_docs/version-27.4/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.4/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.4/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; diff --git a/website/versioned_docs/version-27.5/Es6ClassMocks.md b/website/versioned_docs/version-27.5/Es6ClassMocks.md index f39c8a96ec38..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.5/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.5/Es6ClassMocks.md @@ -141,7 +141,7 @@ jest.mock('./sound-player', () => { ``` :::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word 'mock'. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. @@ -157,7 +157,7 @@ jest.mock('./sound-player', () => { }); ``` -The following will throw a ReferenceError despite using 'mock' in the variable declaration, as the mockSoundPlayer is not wrapped in an arrow function and thus accessed before initialization after hoisting. +The following will throw a `ReferenceError` despite using `mock` in the variable declaration, as the `mockSoundPlayer` is not wrapped in an arrow function and thus accessed before initialization after hoisting. ```javascript import SoundPlayer from './sound-player'; From f1e14b0feb4cc3c75c88895b45b1fcdabc3fa4b6 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 08:32:49 +0100 Subject: [PATCH 3/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c59f244cd403..ed0ad1beb9c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - `[*]` Bundle all `.d.ts` files into a single `index.d.ts` per module ([#12345](https://github.com/facebook/jest/pull/12345)) - `[docs]` Add note about not mixing `done()` with Promises ([#11077](https://github.com/facebook/jest/pull/11077)) - `[docs, examples]` Update React examples to match with the new React guidelines for code examples ([#12217](https://github.com/facebook/jest/pull/12217)) +- `[docs]` Add clarity for module factory hoisting limitations ([#12453](https://github.com/facebook/jest/pull/12453)) - `[expect]` [**BREAKING**] Remove support for importing `build/utils` ([#12323](https://github.com/facebook/jest/pull/12323)) - `[expect]` [**BREAKING**] Migrate to ESM ([#12344](https://github.com/facebook/jest/pull/12344)) - `[expect]` [**BREAKING**] Snapshot matcher types are moved to `@jest/expect` ([#12404](https://github.com/facebook/jest/pull/12404)) @@ -53,7 +54,6 @@ - `[jest-transform]` Update `write-file-atomic` to v4 ([#12357](https://github.com/facebook/jest/pull/12357)) - `[jest-types]` [**BREAKING**] Remove `Config.Glob` and `Config.Path` ([#12406](https://github.com/facebook/jest/pull/12406)) - `[jest]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329)) -- `[docs, website]` Add clarity for module factory limitations ([#12453](https://github.com/facebook/jest/pull/12453)) ### Performance From 32a1fd6647501fe8004b356a0e022860af59726a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 08:52:00 +0100 Subject: [PATCH 4/8] prettier --- docs/Es6ClassMocks.md | 4 +--- website/versioned_docs/version-25.x/Es6ClassMocks.md | 4 +--- website/versioned_docs/version-26.x/Es6ClassMocks.md | 4 +--- website/versioned_docs/version-27.0/Es6ClassMocks.md | 4 +--- website/versioned_docs/version-27.1/Es6ClassMocks.md | 4 +--- website/versioned_docs/version-27.2/Es6ClassMocks.md | 4 +--- website/versioned_docs/version-27.4/Es6ClassMocks.md | 4 +--- website/versioned_docs/version-27.5/Es6ClassMocks.md | 4 +--- 8 files changed, 8 insertions(+), 24 deletions(-) diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-25.x/Es6ClassMocks.md b/website/versioned_docs/version-25.x/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/website/versioned_docs/version-25.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-25.x/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-26.x/Es6ClassMocks.md b/website/versioned_docs/version-26.x/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/website/versioned_docs/version-26.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-26.x/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.0/Es6ClassMocks.md b/website/versioned_docs/version-27.0/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/website/versioned_docs/version-27.0/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.0/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.1/Es6ClassMocks.md b/website/versioned_docs/version-27.1/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/website/versioned_docs/version-27.1/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.1/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.2/Es6ClassMocks.md b/website/versioned_docs/version-27.2/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/website/versioned_docs/version-27.2/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.2/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.4/Es6ClassMocks.md b/website/versioned_docs/version-27.4/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/website/versioned_docs/version-27.4/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.4/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.5/Es6ClassMocks.md b/website/versioned_docs/version-27.5/Es6ClassMocks.md index 95b42b66f8e9..c146b8a393be 100644 --- a/website/versioned_docs/version-27.5/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.5/Es6ClassMocks.md @@ -140,9 +140,7 @@ jest.mock('./sound-player', () => { }); ``` -:::caution -Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). -::: +:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. From 53832199fb0e42d2843e87489ba4569cd08415b0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 08:53:53 +0100 Subject: [PATCH 5/8] Revert "prettier" This reverts commit 32a1fd6647501fe8004b356a0e022860af59726a. --- docs/Es6ClassMocks.md | 4 +++- website/versioned_docs/version-25.x/Es6ClassMocks.md | 4 +++- website/versioned_docs/version-26.x/Es6ClassMocks.md | 4 +++- website/versioned_docs/version-27.0/Es6ClassMocks.md | 4 +++- website/versioned_docs/version-27.1/Es6ClassMocks.md | 4 +++- website/versioned_docs/version-27.2/Es6ClassMocks.md | 4 +++- website/versioned_docs/version-27.4/Es6ClassMocks.md | 4 +++- website/versioned_docs/version-27.5/Es6ClassMocks.md | 4 +++- 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-25.x/Es6ClassMocks.md b/website/versioned_docs/version-25.x/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/website/versioned_docs/version-25.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-25.x/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-26.x/Es6ClassMocks.md b/website/versioned_docs/version-26.x/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/website/versioned_docs/version-26.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-26.x/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.0/Es6ClassMocks.md b/website/versioned_docs/version-27.0/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.0/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.0/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.1/Es6ClassMocks.md b/website/versioned_docs/version-27.1/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.1/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.1/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.2/Es6ClassMocks.md b/website/versioned_docs/version-27.2/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.2/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.2/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.4/Es6ClassMocks.md b/website/versioned_docs/version-27.4/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.4/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.4/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.5/Es6ClassMocks.md b/website/versioned_docs/version-27.5/Es6ClassMocks.md index c146b8a393be..95b42b66f8e9 100644 --- a/website/versioned_docs/version-27.5/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.5/Es6ClassMocks.md @@ -140,7 +140,9 @@ jest.mock('./sound-player', () => { }); ``` -:::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: +:::caution +Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). +::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. From 71bece2d03b76359cba3840cfe652ed545bdba36 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 08:55:02 +0100 Subject: [PATCH 6/8] disable prettier --- docs/Es6ClassMocks.md | 1 + website/versioned_docs/version-25.x/Es6ClassMocks.md | 1 + website/versioned_docs/version-26.x/Es6ClassMocks.md | 1 + website/versioned_docs/version-27.0/Es6ClassMocks.md | 1 + website/versioned_docs/version-27.1/Es6ClassMocks.md | 1 + website/versioned_docs/version-27.2/Es6ClassMocks.md | 1 + website/versioned_docs/version-27.4/Es6ClassMocks.md | 1 + website/versioned_docs/version-27.5/Es6ClassMocks.md | 1 + 8 files changed, 8 insertions(+) diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: diff --git a/website/versioned_docs/version-25.x/Es6ClassMocks.md b/website/versioned_docs/version-25.x/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/website/versioned_docs/version-25.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-25.x/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: diff --git a/website/versioned_docs/version-26.x/Es6ClassMocks.md b/website/versioned_docs/version-26.x/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/website/versioned_docs/version-26.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-26.x/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: diff --git a/website/versioned_docs/version-27.0/Es6ClassMocks.md b/website/versioned_docs/version-27.0/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/website/versioned_docs/version-27.0/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.0/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: diff --git a/website/versioned_docs/version-27.1/Es6ClassMocks.md b/website/versioned_docs/version-27.1/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/website/versioned_docs/version-27.1/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.1/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: diff --git a/website/versioned_docs/version-27.2/Es6ClassMocks.md b/website/versioned_docs/version-27.2/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/website/versioned_docs/version-27.2/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.2/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: diff --git a/website/versioned_docs/version-27.4/Es6ClassMocks.md b/website/versioned_docs/version-27.4/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/website/versioned_docs/version-27.4/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.4/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: diff --git a/website/versioned_docs/version-27.5/Es6ClassMocks.md b/website/versioned_docs/version-27.5/Es6ClassMocks.md index 95b42b66f8e9..54d4e47cd077 100644 --- a/website/versioned_docs/version-27.5/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.5/Es6ClassMocks.md @@ -140,6 +140,7 @@ jest.mock('./sound-player', () => { }); ``` + :::caution Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). ::: From 822a9d9a2482b6b736196202d30d2f4cc63014ae Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 08:56:40 +0100 Subject: [PATCH 7/8] chore: follow advice: https://docusaurus.io/docs/markdown-features/admonitions#usage-with-prettier --- docs/Es6ClassMocks.md | 3 ++- website/versioned_docs/version-25.x/Es6ClassMocks.md | 3 ++- website/versioned_docs/version-26.x/Es6ClassMocks.md | 3 ++- website/versioned_docs/version-27.0/Es6ClassMocks.md | 3 ++- website/versioned_docs/version-27.1/Es6ClassMocks.md | 3 ++- website/versioned_docs/version-27.2/Es6ClassMocks.md | 3 ++- website/versioned_docs/version-27.4/Es6ClassMocks.md | 3 ++- website/versioned_docs/version-27.5/Es6ClassMocks.md | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-25.x/Es6ClassMocks.md b/website/versioned_docs/version-25.x/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/website/versioned_docs/version-25.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-25.x/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-26.x/Es6ClassMocks.md b/website/versioned_docs/version-26.x/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/website/versioned_docs/version-26.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-26.x/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.0/Es6ClassMocks.md b/website/versioned_docs/version-27.0/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/website/versioned_docs/version-27.0/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.0/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.1/Es6ClassMocks.md b/website/versioned_docs/version-27.1/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/website/versioned_docs/version-27.1/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.1/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.2/Es6ClassMocks.md b/website/versioned_docs/version-27.2/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/website/versioned_docs/version-27.2/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.2/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.4/Es6ClassMocks.md b/website/versioned_docs/version-27.4/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/website/versioned_docs/version-27.4/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.4/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. diff --git a/website/versioned_docs/version-27.5/Es6ClassMocks.md b/website/versioned_docs/version-27.5/Es6ClassMocks.md index 54d4e47cd077..35b71b2d7164 100644 --- a/website/versioned_docs/version-27.5/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.5/Es6ClassMocks.md @@ -140,9 +140,10 @@ jest.mock('./sound-player', () => { }); ``` - :::caution + Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents access to out-of-scope variables. By default, you cannot first define a variable and then use it in the factory. Jest will disable this check for variables that start with the word `mock`. However, it is still up to you to guarantee that they will be initialized on time. Be aware of [Temporal Dead Zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). + ::: For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. From ade291b5cb53b4513e34d6e814c47c1050d5e743 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 09:00:37 +0100 Subject: [PATCH 8/8] backticks --- docs/Es6ClassMocks.md | 2 +- website/versioned_docs/version-25.x/Es6ClassMocks.md | 2 +- website/versioned_docs/version-26.x/Es6ClassMocks.md | 2 +- website/versioned_docs/version-27.0/Es6ClassMocks.md | 2 +- website/versioned_docs/version-27.1/Es6ClassMocks.md | 2 +- website/versioned_docs/version-27.2/Es6ClassMocks.md | 2 +- website/versioned_docs/version-27.4/Es6ClassMocks.md | 2 +- website/versioned_docs/version-27.5/Es6ClassMocks.md | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail diff --git a/website/versioned_docs/version-25.x/Es6ClassMocks.md b/website/versioned_docs/version-25.x/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/website/versioned_docs/version-25.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-25.x/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail diff --git a/website/versioned_docs/version-26.x/Es6ClassMocks.md b/website/versioned_docs/version-26.x/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/website/versioned_docs/version-26.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-26.x/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail diff --git a/website/versioned_docs/version-27.0/Es6ClassMocks.md b/website/versioned_docs/version-27.0/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/website/versioned_docs/version-27.0/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.0/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail diff --git a/website/versioned_docs/version-27.1/Es6ClassMocks.md b/website/versioned_docs/version-27.1/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/website/versioned_docs/version-27.1/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.1/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail diff --git a/website/versioned_docs/version-27.2/Es6ClassMocks.md b/website/versioned_docs/version-27.2/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/website/versioned_docs/version-27.2/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.2/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail diff --git a/website/versioned_docs/version-27.4/Es6ClassMocks.md b/website/versioned_docs/version-27.4/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/website/versioned_docs/version-27.4/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.4/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail diff --git a/website/versioned_docs/version-27.5/Es6ClassMocks.md b/website/versioned_docs/version-27.5/Es6ClassMocks.md index 35b71b2d7164..ad2fe2103018 100644 --- a/website/versioned_docs/version-27.5/Es6ClassMocks.md +++ b/website/versioned_docs/version-27.5/Es6ClassMocks.md @@ -146,7 +146,7 @@ Since calls to `jest.mock()` are hoisted to the top of the file, Jest prevents a ::: -For example, the following will throw an out-of-scope error due to the use of 'fake' instead of 'mock' in the variable declaration. +For example, the following will throw an out-of-scope error due to the use of `fake` instead of `mock` in the variable declaration. ```javascript // Note: this will fail