-
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.
- Loading branch information
Matt Seccafien
committed
Jul 7, 2019
1 parent
e901d03
commit 31d6b20
Showing
6 changed files
with
524 additions
and
1 deletion.
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,53 @@ | ||
# Disallow conditional logic. (no-if) | ||
|
||
Conditional logic in tests is usually an indication that a test is attempting to | ||
cover too much, and not testing the logic it intends to. Each branch of code | ||
executing within an if statement will usually be better served by a test devoted | ||
to it. | ||
|
||
Conditionals are often used in to satisfy the typescript type checker when using | ||
a non-null assertion operator (!) would work. | ||
|
||
## Rule Details | ||
|
||
This rule prevents the use of if/ else statements and conditional (ternary) | ||
operations in tests. | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
it('foo', () => { | ||
if ('bar') { | ||
// an if statement here is invalid | ||
// you are probably testing too much | ||
} | ||
}); | ||
|
||
it('foo', () => { | ||
const bar = foo ? 'bar' : null; | ||
}); | ||
``` | ||
|
||
These patterns would not be considered warnings: | ||
|
||
```js | ||
it('foo', () => { | ||
// only test the 'foo' case | ||
}); | ||
|
||
it('bar', () => { | ||
// test the 'bar' case separately | ||
}); | ||
|
||
it('foo', () => { | ||
function foo(bar) { | ||
// nested functions are valid | ||
return foo ? bar : null; | ||
} | ||
}); | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you do not wish to prevent the use of if statements in tests, you can safely | ||
disable this rule. |
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
Oops, something went wrong.