Skip to content

Commit

Permalink
docs: Grammatical Corrections to Async Docs Page (#9679)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Justice committed Mar 25, 2020
1 parent 682e310 commit 677b763
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -49,6 +49,7 @@
### Chore & Maintenance

- `[docs]` Warn about unexpected behavior / bug of node-notifier when using the `notify` options.
- `[docs]` Grammatical corrections to Async docs page. ([#9679](https://github.com/facebook/jest/pull/9679))
- `[jest-resolver]` Use `resolve` package to implement custom module resolution ([#9520](https://github.com/facebook/jest/pull/9520))
- `[jest-runtime]` Move execution of `setupFiles` to `jest-runner` ([#9596](https://github.com/facebook/jest/pull/9596))
- `[@jest/reporters]` Remove unused dependencies and type exports ([#9462](https://github.com/facebook/jest/pull/9462))
Expand Down
6 changes: 3 additions & 3 deletions docs/TestingAsyncCode.md
Expand Up @@ -45,7 +45,7 @@ test('the data is peanut butter', done => {

If `done()` is never called, the test will fail (with timeout error), which is what you want to happen.

In case `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 `try` block and pass error in `catch` block to `done`. Otherwise, we end up with opaque timeout error and no knowledge of what value was received by `expect(data)`.
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)`.

## Promises

Expand All @@ -63,7 +63,7 @@ test('the data is peanut butter', () => {

Be sure to return the promise - if you omit this `return` statement, your test will complete before the promise returned from `fetchData` resolves and then() has a chance to execute the callback.

If you expect a promise to be rejected use the `.catch` method. Make sure to add `expect.assertions` to verify that a certain number of assertions are called. Otherwise a fulfilled promise would not fail the test.
If you expect a promise to be rejected, use the `.catch` method. Make sure to add `expect.assertions` to verify that a certain number of assertions are called. Otherwise a fulfilled promise would not fail the test.

```js
test('the fetch fails with an error', () => {
Expand All @@ -84,7 +84,7 @@ test('the data is peanut butter', () => {

Be sure to return the assertion—if you omit this `return` statement, your test will complete before the promise returned from `fetchData` is resolved and then() has a chance to execute the callback.

If you expect a promise to be rejected use the `.rejects` matcher. It works analogically to the `.resolves` matcher. If the promise is fulfilled, the test will automatically fail.
If you expect a promise to be rejected, use the `.rejects` matcher. It works analogically to the `.resolves` matcher. If the promise is fulfilled, the test will automatically fail.

```js
test('the fetch fails with an error', () => {
Expand Down

0 comments on commit 677b763

Please sign in to comment.