From d8beae42c2e66cbdc2104639d209c2890da59907 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Tue, 29 May 2018 13:26:01 +0100 Subject: [PATCH 1/4] Update jest-each docs for printf usage --- docs/GlobalAPI.md | 32 ++++++++++++++++++++------- packages/jest-each/README.md | 43 +++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 826755904c86..78c1208c95e3 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -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); @@ -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); @@ -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 @@ -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); }, @@ -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); }, @@ -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 }, diff --git a/packages/jest-each/README.md b/packages/jest-each/README.md index 8119e6d4b509..d0ed999de85b 100644 --- a/packages/jest-each/README.md +++ b/packages/jest-each/README.md @@ -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) --- @@ -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)` @@ -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 @@ -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); }, @@ -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); }, @@ -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); }, @@ -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); @@ -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); @@ -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); @@ -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); From 22ae5a3501b08e1ba6a8a8b193685bbc70e777bf Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Tue, 29 May 2018 13:29:18 +0100 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a68d6486cb6..27da39f65649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) From 9a21b6a11ac17fb01c656e241962d1f93b7479f3 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Tue, 29 May 2018 15:58:35 +0100 Subject: [PATCH 3/4] Regenerate 23.0 docs --- website/versioned_docs/version-23.0/CLI.md | 2 +- .../versioned_docs/version-23.0/GlobalAPI.md | 32 ++++++++++++++----- .../version-23.0/WatchPlugins.md | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/website/versioned_docs/version-23.0/CLI.md b/website/versioned_docs/version-23.0/CLI.md index 183e6b8d98ea..d685ba087e83 100644 --- a/website/versioned_docs/version-23.0/CLI.md +++ b/website/versioned_docs/version-23.0/CLI.md @@ -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` diff --git a/website/versioned_docs/version-23.0/GlobalAPI.md b/website/versioned_docs/version-23.0/GlobalAPI.md index 5a9211c9be17..a7b37cd45aa1 100644 --- a/website/versioned_docs/version-23.0/GlobalAPI.md +++ b/website/versioned_docs/version-23.0/GlobalAPI.md @@ -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); @@ -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); @@ -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 @@ -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); }, @@ -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); }, @@ -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 }, diff --git a/website/versioned_docs/version-23.0/WatchPlugins.md b/website/versioned_docs/version-23.0/WatchPlugins.md index 7d1fb0224f3c..f05e057df2c3 100644 --- a/website/versioned_docs/version-23.0/WatchPlugins.md +++ b/website/versioned_docs/version-23.0/WatchPlugins.md @@ -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', }; } From 29950fe0838617679d939704a95d3d6619fbcc9f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 29 May 2018 21:20:29 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4be3e8ec83..f1c33291235b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,8 @@ ### 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)) +* `[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))