Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Reword 3-argument jest.spyOn description #5255

Merged
merged 4 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
* `[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
13 changes: 9 additions & 4 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 **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!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move comment above? same with "setter"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! Fooled by partial git diff from the email

return true;
},
};
Expand All @@ -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;
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