From fbacd3a590add663fa021f2aa056e11e3c44a091 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Fri, 12 Oct 2018 15:44:02 +0100 Subject: [PATCH 1/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d783094aacb2..92ecc5ee0e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ ### Chore & Maintenance +- `[docs]` Add synchronous test.each setup ([#7150](https://github.com/facebook/jest/pull/7150)) - `[docs]` Add `this.extend` to the Custom Matchers API reference ([#7130](https://github.com/facebook/jest/pull/7130)) - `[docs]` Fix default value for `coverageReporters` value in configuration docs ([#7126](https://github.com/facebook/jest/pull/7126)) - `[docs]` Add link for jest-extended in expect docs ([#7078](https://github.com/facebook/jest/pull/7078)) From 0c8325c5393f6296275ae6f5fe8f9edb78398690 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Fri, 12 Oct 2018 17:54:53 +0100 Subject: [PATCH 2/4] Add synchronous test troubeshooting --- docs/Troubleshooting.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/Troubleshooting.md b/docs/Troubleshooting.md index 72caef20636f..c3c13c3695c6 100644 --- a/docs/Troubleshooting.md +++ b/docs/Troubleshooting.md @@ -192,6 +192,23 @@ Jest takes advantage of new features added to Node 6. We recommend that you upgr Make sure you are not using the `babel-plugin-istanbul` plugin. Jest wraps Istanbul, and therefore also tells Istanbul what files to instrument with coverage collection. When using `babel-plugin-istanbul`, every file that is processed by Babel will have coverage collection code, hence it is not being ignored by `coveragePathIgnorePatterns`. +## Defining Tests + +Tests much be defined synchronously for Jest to be able to collect your tests. + +This means when you are using `test.each` you cannot set the table asynchronously within a `beforeEach` / `beforeAll`. + +As an example to show why this is the case, imagine we wrote a test like so: + +```js +// Don't do this it will not work +setTimeout(() => { + it('passes', () => expect(1).toBe(1)); +}, 0); +``` + +When Jest runs your test to collect the `test`s it will not find any because we have set the definition to happen asynchronously on the next tick of the event loop. + ## Still unresolved? See [Help](/help.html). From 72fd039e972a465b2cefa5d21ee264ea0c44824c Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Fri, 12 Oct 2018 17:58:19 +0100 Subject: [PATCH 3/4] Regenerate troubleshooting docs --- .../version-23.6/Troubleshooting.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/website/versioned_docs/version-23.6/Troubleshooting.md b/website/versioned_docs/version-23.6/Troubleshooting.md index 774648e75758..a072a054d257 100644 --- a/website/versioned_docs/version-23.6/Troubleshooting.md +++ b/website/versioned_docs/version-23.6/Troubleshooting.md @@ -193,6 +193,23 @@ Jest takes advantage of new features added to Node 6. We recommend that you upgr Make sure you are not using the `babel-plugin-istanbul` plugin. Jest wraps Istanbul, and therefore also tells Istanbul what files to instrument with coverage collection. When using `babel-plugin-istanbul`, every file that is processed by Babel will have coverage collection code, hence it is not being ignored by `coveragePathIgnorePatterns`. +## Defining Tests + +Tests much be defined synchronously for Jest to be able to collect your tests. + +This means when you are using `test.each` you cannot set the table asynchronously within a `beforeEach` / `beforeAll`. + +As an example to show why this is the case, imagine we wrote a test like so: + +```js +// Don't do this it will not work +setTimeout(() => { + it('passes', () => expect(1).toBe(1)); +}, 0); +``` + +When Jest runs your test to collect the `test`s it will not find any because we have set the definition to happen asynchronously on the next tick of the event loop. + ## Still unresolved? See [Help](/help.html). From 716bc5f143f1aa64a81f07f307afeb031a389d50 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Sun, 14 Oct 2018 11:42:13 +0100 Subject: [PATCH 4/4] Reorder synchronous test docs --- docs/Troubleshooting.md | 6 +++--- website/versioned_docs/version-23.6/Troubleshooting.md | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/Troubleshooting.md b/docs/Troubleshooting.md index c3c13c3695c6..d82a50ae9162 100644 --- a/docs/Troubleshooting.md +++ b/docs/Troubleshooting.md @@ -194,9 +194,7 @@ Make sure you are not using the `babel-plugin-istanbul` plugin. Jest wraps Istan ## Defining Tests -Tests much be defined synchronously for Jest to be able to collect your tests. - -This means when you are using `test.each` you cannot set the table asynchronously within a `beforeEach` / `beforeAll`. +Tests must be defined synchronously for Jest to be able to collect your tests. As an example to show why this is the case, imagine we wrote a test like so: @@ -209,6 +207,8 @@ setTimeout(() => { When Jest runs your test to collect the `test`s it will not find any because we have set the definition to happen asynchronously on the next tick of the event loop. +_Note:_ This means when you are using `test.each` you cannot set the table asynchronously within a `beforeEach` / `beforeAll`. + ## Still unresolved? See [Help](/help.html). diff --git a/website/versioned_docs/version-23.6/Troubleshooting.md b/website/versioned_docs/version-23.6/Troubleshooting.md index a072a054d257..1698f4814aa2 100644 --- a/website/versioned_docs/version-23.6/Troubleshooting.md +++ b/website/versioned_docs/version-23.6/Troubleshooting.md @@ -195,9 +195,7 @@ Make sure you are not using the `babel-plugin-istanbul` plugin. Jest wraps Istan ## Defining Tests -Tests much be defined synchronously for Jest to be able to collect your tests. - -This means when you are using `test.each` you cannot set the table asynchronously within a `beforeEach` / `beforeAll`. +Tests must be defined synchronously for Jest to be able to collect your tests. As an example to show why this is the case, imagine we wrote a test like so: @@ -210,6 +208,10 @@ setTimeout(() => { When Jest runs your test to collect the `test`s it will not find any because we have set the definition to happen asynchronously on the next tick of the event loop. +_Note:_ This means when you are using `test.each` you cannot set the table asynchronously within a `beforeEach` / `beforeAll`. + +When Jest runs your test to collect the `test`s it will not find any because we have set the definition to happen asynchronously on the next tick of the event loop. + ## Still unresolved? See [Help](/help.html).