From 71ce740467366e213178df7ba33802649edf7cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 8 Jan 2018 23:44:23 +0100 Subject: [PATCH 1/4] docs: Reword spyOn with accessType --- docs/JestObjectAPI.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 64dcfbf982e5..039c4609e3de 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -420,9 +420,9 @@ test('plays video', () => { ``` ### `jest.spyOn(object, methodName, accessType?)` -##### available in Jest **x.x.x+** +##### available in Jest **22.1.0+** -Since Jest x.x.x+, the `jest.spyOn` method takes an optional third argument that can be `'get'` or `'get'` in order to install a spy as a getter or a setter respectively. This is also needed when you need a spy an existing getter/setter method. +Since Jest 22.1.0+, the `jest.spyOn` method takes an optional third argument of `accessType` that can be either `'get'` or `'set'`, which proves to be useful when you want to spy on a getter or a setter, respectively. Example: From 76f9a8d8c7b0b9e7b652b3dcc98e6a5cee57eda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 9 Jan 2018 08:57:27 +0100 Subject: [PATCH 2/4] Run lint on .md files --- CHANGELOG.md | 22 +++++++++------ docs/Configuration.md | 13 +++++---- docs/JestObjectAPI.md | 13 ++++++--- docs/SetupAndTeardown.md | 58 +++++++++++++++++++++------------------- 4 files changed, 60 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7048c2c3b311..323ee638b264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,17 @@ ### Fixes -* `[expect]` Fail test when the types of `stringContaining` and `stringMatching` matchers do not match. -* `[jest-cli]` Treat dumb terminals as noninteractive ([#5237](https://github.com/facebook/jest/pull/5237)) +* `[expect]` Fail test when the types of `stringContaining` and `stringMatching` + matchers do not match. +* `[jest-cli]` Treat dumb terminals as noninteractive + ([#5237](https://github.com/facebook/jest/pull/5237)) * `[jest-cli]` `jest --onlyChanged --changedFilesWithAncestor` now also works with git. ([#5189](https://github.com/facebook/jest/pull/5189)) * `[jest-config]` fix unexpected condition to avoid infinite recursion in Windows platform. ([#5161](https://github.com/facebook/jest/pull/5161)) -* `[jest-config]` Escape parentheses and other glob characters in `rootDir` before interpolating with `testMatch`. ([#4838](https://github.com/facebook/jest/issues/4838)) +* `[jest-config]` Escape parentheses and other glob characters in `rootDir` + before interpolating with `testMatch`. + ([#4838](https://github.com/facebook/jest/issues/4838)) * `[jest-regex-util]` Fix breaking change in `--testPathPattern` ([#5230](https://github.com/facebook/jest/pull/5230)) * `[expect]` Do not override `Error` stack (with `Error.captureStackTrace`) for @@ -33,15 +37,17 @@ * `[jest-runner]` test environments are now passed a new `options` parameter. Currently this only has the `console` which is the test console that Jest will expose to tests. ([#5223](https://github.com/facebook/jest/issues/5223)) -* `[jest-environment-jsdom]` pass the `options.console` to a custom - instance of `virtualConsole` so jsdom is using the same console as the - test. ([#5223](https://github.com/facebook/jest/issues/5223)) +* `[jest-environment-jsdom]` pass the `options.console` to a custom instance of + `virtualConsole` so jsdom is using the same console as the test. + ([#5223](https://github.com/facebook/jest/issues/5223)) ### Chore & Maintenance * `[docs]` Describe the order of execution of describe and test blocks. - ([#5217](https://github.com/facebook/jest/pull/5217), [#5238](https://github.com/facebook/jest/pull/5238)) -* `[docs]` Add a note on `moduleNameMapper` ordering. ([#5249](https://github.com/facebook/jest/pull/5249)) + ([#5217](https://github.com/facebook/jest/pull/5217), + [#5238](https://github.com/facebook/jest/pull/5238)) +* `[docs]` Add a note on `moduleNameMapper` ordering. + ([#5249](https://github.com/facebook/jest/pull/5249)) ## jest 22.0.4 diff --git a/docs/Configuration.md b/docs/Configuration.md index 5641f487e6b4..a49d11769c81 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -386,8 +386,8 @@ Example: } ``` -The order in which the mappings are defined matters. Patterns are checked one -by one until one fits. The most specific rule should be listed first. +The order in which the mappings are defined matters. Patterns are checked one by +one until one fits. The most specific rule should be listed first. _Note: If you provide module name without boundaries `^$` it may cause hard to spot errors. E.g. `relay` will replace all modules which contain `relay` as a @@ -795,9 +795,9 @@ test('use jsdom in this test file', () => { You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and -`runScript` methods. You can also pass variables from this module to your -test suites by assigning them to `this.global` object – this will -make them available in your test suites as global variables. +`runScript` methods. You can also pass variables from this module to your test +suites by assigning them to `this.global` object – this will make them +available in your test suites as global variables. ##### available in Jest **22.0.0+** @@ -839,8 +839,7 @@ let someGlobalObject; beforeAll(() => { someGlobalObject = global.someGlobalObject; -}) - +}); ``` ### `testEnvironmentOptions` [Object] diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 039c4609e3de..e9e2192b8cb1 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -420,15 +420,19 @@ test('plays video', () => { ``` ### `jest.spyOn(object, methodName, accessType?)` + ##### available in Jest **22.1.0+** -Since Jest 22.1.0+, the `jest.spyOn` method takes an optional third argument of `accessType` that can be either `'get'` or `'set'`, which proves to be useful when you want to spy on a getter or a setter, respectively. +Since Jest 22.1.0+, the `jest.spyOn` method takes an optional third argument of +`accessType` that can be either `'get'` or `'set'`, which proves to be useful +when you want to spy on a getter or a setter, respectively. Example: ```js const video = { - get play() { // it's a getter! + get play() { + // it's a getter! return true; }, }; @@ -437,12 +441,13 @@ module.exports = video; const audio = { _volume: false, - set volume(value) { // it's a setter! + set volume(value) { + // it's a setter! this._volume = value; }, get volume() { return this._volume; - } + }, }; module.exports = video; diff --git a/docs/SetupAndTeardown.md b/docs/SetupAndTeardown.md index 2307507f2252..c5d34e9f75a4 100644 --- a/docs/SetupAndTeardown.md +++ b/docs/SetupAndTeardown.md @@ -149,39 +149,43 @@ describe('Scoped / Nested block', () => { ### Order of execution of describe and test blocks -Jest executes all describe handlers in a test file *before* it executes any of the actual tests. This is another reason to do setup and teardown in `before*` and `after*` handlers rather in the describe blocks. Once the describe blocks are complete, by default Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on. +Jest executes all describe handlers in a test file _before_ it executes any of +the actual tests. This is another reason to do setup and teardown in `before*` +and `after*` handlers rather in the describe blocks. Once the describe blocks +are complete, by default Jest runs all the tests serially in the order they were +encountered in the collection phase, waiting for each to finish and be tidied up +before moving on. Consider the following illustrative test file and output: ```js describe('outer', () => { + console.log('describe outer-a'); + + describe('describe inner 1', () => { + console.log('describe inner 1'); + test('test 1', () => { + console.log('test for describe inner 1'); + expect(true).toEqual(true); + }); + }); + + console.log('describe outer-b'); + + test('test 1', () => { + console.log('test for describe outer'); + expect(true).toEqual(true); + }); + + describe('describe inner 2', () => { + console.log('describe inner 2'); + test('test for describe inner 2', () => { + console.log('test for describe inner 2'); + expect(false).toEqual(false); + }); + }); - console.log('describe outer-a'); - - describe('describe inner 1', () => { - console.log('describe inner 1'); - test('test 1', () => { - console.log('test for describe inner 1'); - expect(true).toEqual(true); - }); - }); - - console.log('describe outer-b'); - - test('test 1', () => { - console.log('test for describe outer'); - expect(true).toEqual(true); - }); - - describe('describe inner 2', () => { - console.log('describe inner 2'); - test('test for describe inner 2', () => { - console.log('test for describe inner 2'); - expect(false).toEqual(false); - }) - }); - - console.log('describe outer-c'); + console.log('describe outer-c'); }); // describe outer-a From 738d9e899d7816738a69a02d207efa2624a01331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 9 Jan 2018 08:59:06 +0100 Subject: [PATCH 3/4] Shift comments placement --- docs/JestObjectAPI.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index e9e2192b8cb1..0ef8f8801478 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -431,8 +431,8 @@ Example: ```js const video = { + // it's a getter! get play() { - // it's a getter! return true; }, }; @@ -441,8 +441,8 @@ module.exports = video; const audio = { _volume: false, + // it's a setter! set volume(value) { - // it's a setter! this._volume = value; }, get volume() { From fd9d6a30cdd54f1c6e26e679198312ff1b59e01c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 9 Jan 2018 09:10:30 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 323ee638b264..fcb07c0a7467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Fixes * `[expect]` Fail test when the types of `stringContaining` and `stringMatching` - matchers do not match. + matchers do not match. ([#5069](https://github.com/facebook/jest/pull/5069)) * `[jest-cli]` Treat dumb terminals as noninteractive ([#5237](https://github.com/facebook/jest/pull/5237)) * `[jest-cli]` `jest --onlyChanged --changedFilesWithAncestor` now also works