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

Update jest-each serializing docs #6337

Merged
merged 5 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Chore & Maintenance

* `[jest-each]` Update jest-each docs for serialising values into titles ([#6337](https://github.com/facebook/jest/pull/6337))
* `[jest-circus]` Add dependency on jest-each ([#6309](https://github.com/facebook/jest/pull/6309))
* `[filenames]` Rename "integration-tests" to "e2e" ([#6315](https://github.com/facebook/jest/pull/6315))
* `[docs]` Mention the use of commit hash with `--changedSince` flag ([#6330](https://github.com/facebook/jest/pull/6330))
Expand Down
32 changes: 24 additions & 8 deletions docs/GlobalAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,22 @@ Use `describe.each` if you keep duplicating the same test suites with different
#### 1. `describe.each(table)(name, fn)`

* `table`: `Array` of Arrays with the arguments that are passed into the `fn` for each row.
* `name`: `String` the title of the test suite, use `%s` to positionally inject test data into the suite title.
* `name`: `String` the title of the test suite.
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* `fn`: `Function` the suite of tests to be ran, this is the function that will receive the parameters in each row as function arguments.

Example:

```js
describe.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
Expand Down Expand Up @@ -320,7 +328,7 @@ Use `describe.only.each` if you want to only run specific tests suites of data d

```js
describe.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
Expand Down Expand Up @@ -388,7 +396,7 @@ Use `describe.skip.each` if you want to stop running a suite of data driven test

```js
describe.skip.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected); // will not be ran
Expand Down Expand Up @@ -467,14 +475,22 @@ Use `test.each` if you keep duplicating the same test with different data. `test
#### 1. `test.each(table)(name, fn)`

* `table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row.
* `name`: `String` the title of the test block, use `%s` to positionally inject parameter values into the test title.
* `name`: `String` the title of the test block.
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* `fn`: `Function` the test to be ran, this is the function that will receive the parameters in each row as function arguments.

Example:

```js
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
Expand Down Expand Up @@ -538,7 +554,7 @@ Use `test.only.each` if you want to only run specific tests with different test

```js
test.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
Expand Down Expand Up @@ -600,7 +616,7 @@ Use `test.skip.each` if you want to stop running a collection of data driven tes

```js
test.skip.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected); // will not be ran
},
Expand Down
43 changes: 33 additions & 10 deletions packages/jest-each/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ jest-each allows you to provide multiple arguments to your `test`/`describe` whi
* `.describe.skip` to skip the parameterised suite of tests
* Also under the aliases: `.xdescribe`
* Asynchronous tests with `done`
* Unique test titles with: [Node util.format](https://nodejs.org/api/util.html#util_util_format_format_args)
* Unique test titles with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* 🖖 Spock like data tables with [Tagged Template Literals](#tagged-template-literal-of-rows)

---
Expand Down Expand Up @@ -91,7 +98,15 @@ const each = require('jest-each');

##### `.test`:

* name: `String` the title of the `test`, use `%s` in the name string to positionally inject parameter values into the test title
* name: `String` the title of the `test`.
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments

#### `each([parameters]).describe(name, suiteFn)`
Expand All @@ -102,7 +117,15 @@ const each = require('jest-each');

##### `.describe`:

* name: `String` the title of the `describe`, use `%s` in the name string to positionally inject parameter values into the suite title
* name: `String` the title of the `describe`
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* suiteFn: `Function` the suite of `test`/`it`s to be ran, this is the function that will receive the parameters in each row as function arguments

### Usage
Expand All @@ -113,7 +136,7 @@ Alias: `.it(name, fn)`

```js
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).test(
'returns the result of adding %s to %s',
'returns the result of adding %d to %d',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
Expand All @@ -126,7 +149,7 @@ Aliases: `.it.only(name, fn)` or `.fit(name, fn)`

```js
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).test.only(
'returns the result of adding %s to %s',
'returns the result of adding %d to %d',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
Expand All @@ -139,7 +162,7 @@ Aliases: `.it.skip(name, fn)` or `.xit(name, fn)` or `.xtest(name, fn)`

```js
each([[1, 1, 2][(1, 2, 3)], [2, 1, 3]]).test.skip(
'returns the result of adding %s to %s',
'returns the result of adding %d to %d',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
Expand All @@ -152,7 +175,7 @@ Alias: `.it(name, fn(done))`

```js
each([['hello'], ['mr'], ['spy']]).test(
'gives 007 secret message ',
'gives 007 secret message: %s',
(str, done) => {
const asynchronousSpy = message => {
expect(message).toBe(str);
Expand All @@ -167,7 +190,7 @@ each([['hello'], ['mr'], ['spy']]).test(

```js
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).describe(
'.add(%s, %s)',
'.add(%d, %d)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
Expand All @@ -192,7 +215,7 @@ Aliases: `.fdescribe(name, fn)`

```js
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).describe.only(
'.add(%s, %s)',
'.add(%d, %d)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
Expand All @@ -207,7 +230,7 @@ Aliases: `.xdescribe(name, fn)`

```js
each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).describe.skip(
'.add(%s, %s)',
'.add(%d, %d)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-23.0/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Runs tests related to the current changes and the changes made in the last commi

### `--changedSince`

Runs tests related to the changes since the provided branch or commit hash. If the current branch has diverged from the given branch, then only changes made locally will be tested. Behaves similarly to `--onlyChanged`.
Runs tests related the changes since the provided branch. If the current branch has diverged from the given branch, then only changes made locally will be tested. Behaves similarly to `--onlyChanged`.

### `--ci`

Expand Down
32 changes: 24 additions & 8 deletions website/versioned_docs/version-23.0/GlobalAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,22 @@ Use `describe.each` if you keep duplicating the same test suites with different
#### 1. `describe.each(table)(name, fn)`

* `table`: `Array` of Arrays with the arguments that are passed into the `fn` for each row.
* `name`: `String` the title of the test suite, use `%s` to positionally inject test data into the suite title.
* `name`: `String` the title of the test suite.
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* `fn`: `Function` the suite of tests to be ran, this is the function that will receive the parameters in each row as function arguments.

Example:

```js
describe.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
Expand Down Expand Up @@ -321,7 +329,7 @@ Use `describe.only.each` if you want to only run specific tests suites of data d

```js
describe.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
Expand Down Expand Up @@ -389,7 +397,7 @@ Use `describe.skip.each` if you want to stop running a suite of data driven test

```js
describe.skip.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected); // will not be ran
Expand Down Expand Up @@ -468,14 +476,22 @@ Use `test.each` if you keep duplicating the same test with different data. `test
#### 1. `test.each(table)(name, fn)`

* `table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row.
* `name`: `String` the title of the test block, use `%s` to positionally inject parameter values into the test title.
* `name`: `String` the title of the test block.
* Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
* `%s`- String.
* `%d`- Number.
* `%i` - Integer.
* `%f` - Floating point value.
* `%j` - JSON.
* `%o` - Object.
* `%%` - single percent sign ('%'). This does not consume an argument.
* `fn`: `Function` the test to be ran, this is the function that will receive the parameters in each row as function arguments.

Example:

```js
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
Expand Down Expand Up @@ -539,7 +555,7 @@ Use `test.only.each` if you want to only run specific tests with different test

```js
test.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
Expand Down Expand Up @@ -601,7 +617,7 @@ Use `test.skip.each` if you want to stop running a collection of data driven tes

```js
test.skip.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%s, %s)',
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected); // will not be ran
},
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-23.0/WatchPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ To add a key to the watch menu, implement the `getUsageInfo` method, returning a
class MyWatchPlugin {
getUsageInfo(globalConfig) {
return {
key: 's'.codePointAt(0),
key: 's',
prompt: 'do something',
};
}
Expand Down