Skip to content

Commit

Permalink
docs(no-try-expect): examples and remove Shopify reference
Browse files Browse the repository at this point in the history
  • Loading branch information
cartogram committed Jul 21, 2019
1 parent ae8f6ad commit 32408ad
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions docs/rules/no-try-expect.md
Expand Up @@ -5,9 +5,9 @@ This rule prevents the use of `expect` inside `catch` blocks.
## Rule Details

Expectations inside a `catch` block can be silently skipped. While Jest provides
an `expect.assertions(number)` helper, Shopify rarely uses this feature. Using
`toThrow` concisely guarantees that an exception was thrown, and that its
contents match expectations.
an `expect.assertions(number)` helper, it might be cumbersome to add this to
every single test. Using `toThrow` concisely guarantees that an exception was
thrown, and that its contents match expectations.

The following patterns are warnings:

Expand All @@ -27,6 +27,14 @@ it('bar', async () => {
expect(err).toMatch(/foo error/);
}
});

it('baz', async () => {
try {
await foo();
} catch (err) {
expect(err).toMatchObject({ code: 'MODULE_NOT_FOUND' });
}
});
```

The following patterns are not warnings:
Expand All @@ -39,4 +47,10 @@ it('foo', () => {
it('bar', async () => {
await expect(fooPromise).rejects.toThrow(/foo error/);
});

it('baz', async () => {
expect(() => foo()).toThrow(
expect.objectContaining({ code: 'MODULE_NOT_FOUND' }),
);
});
```

0 comments on commit 32408ad

Please sign in to comment.