-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docs): prefer-expect-assertions rule docs (#49)
* docs: updating docs for prefer-expect-assertions rule * style: minnor formating in prefer-expect-assertions doc * docs: tweaks
- Loading branch information
1 parent
08f93ff
commit d96baca
Showing
2 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Suggest using `expect.assertions()` OR `expect.hasAssertions()` (prefer-expect-assertions) | ||
|
||
Ensure every test to have either `expect.assertions(<number of assertions>)` OR | ||
`expect.hasAssertions()` as its first expression. | ||
|
||
## Rule details | ||
|
||
This rule triggers a warning if, | ||
|
||
* `expect.assertions(<number of assertions>)` OR `expect.hasAssertions()` is not | ||
present as first statement in a test, e.g.: | ||
|
||
```js | ||
test('my test', () => { | ||
expect(someThing()).toEqual('foo'); | ||
}); | ||
``` | ||
|
||
* `expect.assertions(<number of assertions>)` is the first statement in a test | ||
where argument passed to `expect.assertions(<number of assertions>)` is not a | ||
valid number, e.g.: | ||
|
||
```js | ||
test('my test', () => { | ||
expect.assertions('1'); | ||
expect(someThing()).toEqual('foo'); | ||
}); | ||
``` | ||
|
||
### Default configuration | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
test("my test", () => { | ||
expect.assertions("1"); | ||
expect(someThing()).toEqual("foo"); | ||
}); | ||
|
||
test("my test", () => { | ||
expect.(someThing()).toEqual("foo"); | ||
}); | ||
``` | ||
|
||
The following patterns would not be considered warnings: | ||
|
||
```js | ||
test('my test', () => { | ||
expect.assertions(1); | ||
expect(someThing()).toEqual('foo'); | ||
}); | ||
|
||
test('my test', () => { | ||
expect.hasAssertions(); | ||
expect(someThing()).toEqual('foo'); | ||
}); | ||
``` |