From 3ae3a41de6b4756f71e8011c2b7e3e3be16bb575 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 11 Feb 2021 11:28:12 -0700 Subject: [PATCH 1/2] Update TestingAsyncCode.md --- docs/TestingAsyncCode.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/TestingAsyncCode.md b/docs/TestingAsyncCode.md index 2352de9a38c3..7b598d04aac8 100644 --- a/docs/TestingAsyncCode.md +++ b/docs/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +*Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests.* + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. From a58b3e9f18cac473f4e9ee166fca557cf9525dc9 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 11 Feb 2021 11:31:11 -0700 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + docs/TestingAsyncCode.md | 2 +- website/versioned_docs/version-25.x/TestingAsyncCode.md | 2 ++ website/versioned_docs/version-26.x/TestingAsyncCode.md | 2 ++ website/versioned_docs/version-27.0/TestingAsyncCode.md | 2 ++ website/versioned_docs/version-27.1/TestingAsyncCode.md | 2 ++ website/versioned_docs/version-27.2/TestingAsyncCode.md | 2 ++ website/versioned_docs/version-27.4/TestingAsyncCode.md | 2 ++ website/versioned_docs/version-27.5/TestingAsyncCode.md | 2 ++ 9 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1856c8f98ad..214a917d2b47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ - `[jest-snapshot]` [**BREAKING**] Migrate to ESM ([#12342](https://github.com/facebook/jest/pull/12342)) - `[jest-transform]` Update `write-file-atomic` to v4 ([#12357](https://github.com/facebook/jest/pull/12357)) - `[jest]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329)) +- `[docs]` Add note about not mixing `done()` with Promises ([#11077](https://github.com/facebook/jest/pull/11077)) ### Performance diff --git a/docs/TestingAsyncCode.md b/docs/TestingAsyncCode.md index 7b598d04aac8..432db44b3944 100644 --- a/docs/TestingAsyncCode.md +++ b/docs/TestingAsyncCode.md @@ -47,7 +47,7 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. -*Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests.* +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ ## Promises diff --git a/website/versioned_docs/version-25.x/TestingAsyncCode.md b/website/versioned_docs/version-25.x/TestingAsyncCode.md index 2352de9a38c3..432db44b3944 100644 --- a/website/versioned_docs/version-25.x/TestingAsyncCode.md +++ b/website/versioned_docs/version-25.x/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. diff --git a/website/versioned_docs/version-26.x/TestingAsyncCode.md b/website/versioned_docs/version-26.x/TestingAsyncCode.md index 2352de9a38c3..432db44b3944 100644 --- a/website/versioned_docs/version-26.x/TestingAsyncCode.md +++ b/website/versioned_docs/version-26.x/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. diff --git a/website/versioned_docs/version-27.0/TestingAsyncCode.md b/website/versioned_docs/version-27.0/TestingAsyncCode.md index 2352de9a38c3..432db44b3944 100644 --- a/website/versioned_docs/version-27.0/TestingAsyncCode.md +++ b/website/versioned_docs/version-27.0/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. diff --git a/website/versioned_docs/version-27.1/TestingAsyncCode.md b/website/versioned_docs/version-27.1/TestingAsyncCode.md index 2352de9a38c3..432db44b3944 100644 --- a/website/versioned_docs/version-27.1/TestingAsyncCode.md +++ b/website/versioned_docs/version-27.1/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. diff --git a/website/versioned_docs/version-27.2/TestingAsyncCode.md b/website/versioned_docs/version-27.2/TestingAsyncCode.md index 2352de9a38c3..432db44b3944 100644 --- a/website/versioned_docs/version-27.2/TestingAsyncCode.md +++ b/website/versioned_docs/version-27.2/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. diff --git a/website/versioned_docs/version-27.4/TestingAsyncCode.md b/website/versioned_docs/version-27.4/TestingAsyncCode.md index 2352de9a38c3..432db44b3944 100644 --- a/website/versioned_docs/version-27.4/TestingAsyncCode.md +++ b/website/versioned_docs/version-27.4/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. diff --git a/website/versioned_docs/version-27.5/TestingAsyncCode.md b/website/versioned_docs/version-27.5/TestingAsyncCode.md index 2352de9a38c3..432db44b3944 100644 --- a/website/versioned_docs/version-27.5/TestingAsyncCode.md +++ b/website/versioned_docs/version-27.5/TestingAsyncCode.md @@ -47,6 +47,8 @@ If `done()` is never called, the test will fail (with timeout error), which is w If the `expect` statement fails, it throws an error and `done()` is not called. If we want to see in the test log why it failed, we have to wrap `expect` in a `try` block and pass the error in the `catch` block to `done`. Otherwise, we end up with an opaque timeout error that doesn't show what value was received by `expect(data)`. +_Note: `done()` should not be mixed with Promises as this tends to lead to memory leaks in your tests._ + ## Promises If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail.