Skip to content

Commit

Permalink
docs: Reword 3-argument jest.spyOn description (#5255)
Browse files Browse the repository at this point in the history
* docs: Reword spyOn with accessType

* Run lint on .md files

* Shift comments placement

* Update CHANGELOG.md
  • Loading branch information
thymikee authored and cpojer committed Jan 9, 2018
1 parent 2daf8fe commit 6931b0f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
22 changes: 14 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. ([#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
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
Expand All @@ -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

Expand Down
13 changes: 6 additions & 7 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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+**

Expand Down Expand Up @@ -839,8 +839,7 @@ let someGlobalObject;

beforeAll(() => {
someGlobalObject = global.someGlobalObject;
})

});
```

### `testEnvironmentOptions` [Object]
Expand Down
15 changes: 10 additions & 5 deletions docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,19 @@ test('plays video', () => {
```

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

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.
##### 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.

Example:

```js
const video = {
get play() { // it's a getter!
// it's a getter!
get play() {
return true;
},
};
Expand All @@ -437,12 +441,13 @@ module.exports = video;

const audio = {
_volume: false,
set volume(value) { // it's a setter!
// it's a setter!
set volume(value) {
this._volume = value;
},
get volume() {
return this._volume;
}
},
};

module.exports = video;
Expand Down
58 changes: 31 additions & 27 deletions docs/SetupAndTeardown.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6931b0f

Please sign in to comment.