Skip to content

Commit 6931b0f

Browse files
thymikeecpojer
authored andcommitted
docs: Reword 3-argument jest.spyOn description (#5255)
* docs: Reword spyOn with accessType * Run lint on .md files * Shift comments placement * Update CHANGELOG.md
1 parent 2daf8fe commit 6931b0f

File tree

4 files changed

+61
-47
lines changed

4 files changed

+61
-47
lines changed

CHANGELOG.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
### Fixes
44

5-
* `[expect]` Fail test when the types of `stringContaining` and `stringMatching` matchers do not match.
6-
* `[jest-cli]` Treat dumb terminals as noninteractive ([#5237](https://github.com/facebook/jest/pull/5237))
5+
* `[expect]` Fail test when the types of `stringContaining` and `stringMatching`
6+
matchers do not match. ([#5069](https://github.com/facebook/jest/pull/5069))
7+
* `[jest-cli]` Treat dumb terminals as noninteractive
8+
([#5237](https://github.com/facebook/jest/pull/5237))
79
* `[jest-cli]` `jest --onlyChanged --changedFilesWithAncestor` now also works
810
with git. ([#5189](https://github.com/facebook/jest/pull/5189))
911
* `[jest-config]` fix unexpected condition to avoid infinite recursion in
1012
Windows platform. ([#5161](https://github.com/facebook/jest/pull/5161))
11-
* `[jest-config]` Escape parentheses and other glob characters in `rootDir` before interpolating with `testMatch`. ([#4838](https://github.com/facebook/jest/issues/4838))
13+
* `[jest-config]` Escape parentheses and other glob characters in `rootDir`
14+
before interpolating with `testMatch`.
15+
([#4838](https://github.com/facebook/jest/issues/4838))
1216
* `[jest-regex-util]` Fix breaking change in `--testPathPattern`
1317
([#5230](https://github.com/facebook/jest/pull/5230))
1418
* `[expect]` Do not override `Error` stack (with `Error.captureStackTrace`) for
@@ -33,15 +37,17 @@
3337
* `[jest-runner]` test environments are now passed a new `options` parameter.
3438
Currently this only has the `console` which is the test console that Jest will
3539
expose to tests. ([#5223](https://github.com/facebook/jest/issues/5223))
36-
* `[jest-environment-jsdom]` pass the `options.console` to a custom
37-
instance of `virtualConsole` so jsdom is using the same console as the
38-
test. ([#5223](https://github.com/facebook/jest/issues/5223))
40+
* `[jest-environment-jsdom]` pass the `options.console` to a custom instance of
41+
`virtualConsole` so jsdom is using the same console as the test.
42+
([#5223](https://github.com/facebook/jest/issues/5223))
3943

4044
### Chore & Maintenance
4145

4246
* `[docs]` Describe the order of execution of describe and test blocks.
43-
([#5217](https://github.com/facebook/jest/pull/5217), [#5238](https://github.com/facebook/jest/pull/5238))
44-
* `[docs]` Add a note on `moduleNameMapper` ordering. ([#5249](https://github.com/facebook/jest/pull/5249))
47+
([#5217](https://github.com/facebook/jest/pull/5217),
48+
[#5238](https://github.com/facebook/jest/pull/5238))
49+
* `[docs]` Add a note on `moduleNameMapper` ordering.
50+
([#5249](https://github.com/facebook/jest/pull/5249))
4551

4652
## jest 22.0.4
4753

docs/Configuration.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ Example:
386386
}
387387
```
388388

389-
The order in which the mappings are defined matters. Patterns are checked one
390-
by one until one fits. The most specific rule should be listed first.
389+
The order in which the mappings are defined matters. Patterns are checked one by
390+
one until one fits. The most specific rule should be listed first.
391391

392392
_Note: If you provide module name without boundaries `^$` it may cause hard to
393393
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', () => {
795795

796796
You can create your own module that will be used for setting up the test
797797
environment. The module must export a class with `setup`, `teardown` and
798-
`runScript` methods. You can also pass variables from this module to your
799-
test suites by assigning them to `this.global` object – this will
800-
make them available in your test suites as global variables.
798+
`runScript` methods. You can also pass variables from this module to your test
799+
suites by assigning them to `this.global` object – this will make them
800+
available in your test suites as global variables.
801801

802802
##### available in Jest **22.0.0+**
803803

@@ -839,8 +839,7 @@ let someGlobalObject;
839839

840840
beforeAll(() => {
841841
someGlobalObject = global.someGlobalObject;
842-
})
843-
842+
});
844843
```
845844

846845
### `testEnvironmentOptions` [Object]

docs/JestObjectAPI.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,19 @@ test('plays video', () => {
420420
```
421421

422422
### `jest.spyOn(object, methodName, accessType?)`
423-
##### available in Jest **x.x.x+**
424423

425-
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.
424+
##### available in Jest **22.1.0+**
425+
426+
Since Jest 22.1.0+, the `jest.spyOn` method takes an optional third argument of
427+
`accessType` that can be either `'get'` or `'set'`, which proves to be useful
428+
when you want to spy on a getter or a setter, respectively.
426429

427430
Example:
428431

429432
```js
430433
const video = {
431-
get play() { // it's a getter!
434+
// it's a getter!
435+
get play() {
432436
return true;
433437
},
434438
};
@@ -437,12 +441,13 @@ module.exports = video;
437441

438442
const audio = {
439443
_volume: false,
440-
set volume(value) { // it's a setter!
444+
// it's a setter!
445+
set volume(value) {
441446
this._volume = value;
442447
},
443448
get volume() {
444449
return this._volume;
445-
}
450+
},
446451
};
447452

448453
module.exports = video;

docs/SetupAndTeardown.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,39 +149,43 @@ describe('Scoped / Nested block', () => {
149149

150150
### Order of execution of describe and test blocks
151151

152-
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.
152+
Jest executes all describe handlers in a test file _before_ it executes any of
153+
the actual tests. This is another reason to do setup and teardown in `before*`
154+
and `after*` handlers rather in the describe blocks. Once the describe blocks
155+
are complete, by default Jest runs all the tests serially in the order they were
156+
encountered in the collection phase, waiting for each to finish and be tidied up
157+
before moving on.
153158

154159
Consider the following illustrative test file and output:
155160

156161
```js
157162
describe('outer', () => {
163+
console.log('describe outer-a');
164+
165+
describe('describe inner 1', () => {
166+
console.log('describe inner 1');
167+
test('test 1', () => {
168+
console.log('test for describe inner 1');
169+
expect(true).toEqual(true);
170+
});
171+
});
172+
173+
console.log('describe outer-b');
174+
175+
test('test 1', () => {
176+
console.log('test for describe outer');
177+
expect(true).toEqual(true);
178+
});
179+
180+
describe('describe inner 2', () => {
181+
console.log('describe inner 2');
182+
test('test for describe inner 2', () => {
183+
console.log('test for describe inner 2');
184+
expect(false).toEqual(false);
185+
});
186+
});
158187

159-
console.log('describe outer-a');
160-
161-
describe('describe inner 1', () => {
162-
console.log('describe inner 1');
163-
test('test 1', () => {
164-
console.log('test for describe inner 1');
165-
expect(true).toEqual(true);
166-
});
167-
});
168-
169-
console.log('describe outer-b');
170-
171-
test('test 1', () => {
172-
console.log('test for describe outer');
173-
expect(true).toEqual(true);
174-
});
175-
176-
describe('describe inner 2', () => {
177-
console.log('describe inner 2');
178-
test('test for describe inner 2', () => {
179-
console.log('test for describe inner 2');
180-
expect(false).toEqual(false);
181-
})
182-
});
183-
184-
console.log('describe outer-c');
188+
console.log('describe outer-c');
185189
});
186190

187191
// describe outer-a

0 commit comments

Comments
 (0)