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(TestingAsyncCode.md): add note about not mixing done w/promises #11077

Merged
merged 2 commits into from
Feb 15, 2022
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 @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/versioned_docs/version-25.x/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/versioned_docs/version-26.x/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/versioned_docs/version-27.0/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/versioned_docs/version-27.1/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/versioned_docs/version-27.2/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/versioned_docs/version-27.4/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/versioned_docs/version-27.5/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down