Skip to content

feat(rules): adds no-if rule#293

Merged
SimenB merged 3 commits intojest-community:masterfrom
cartogram:no-if
Jul 17, 2019
Merged

feat(rules): adds no-if rule#293
SimenB merged 3 commits intojest-community:masterfrom
cartogram:no-if

Conversation

@cartogram
Copy link
Copy Markdown
Contributor

@cartogram cartogram commented Jul 6, 2019

If statements in tests is usually a bad idea. This PR prevents them.

Examples of incorrect code for this rule:

it('foo', () => {
 if ('bar') {
   // an if statement here is invalid
   // you are probably testing too much
 }
});

it('foo', () => {
 const bar = foo ? 'bar' : null;
});

Examples of correct code for this rule:

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;
 }
});

@cartogram cartogram force-pushed the no-if branch 5 times, most recently from e3d8ac5 to 31d6b20 Compare July 7, 2019 07:05
Copy link
Copy Markdown
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Left a nit, but this looks like a good rule to me 🙂

Comment thread src/rules/no-if.js Outdated
@cartogram cartogram force-pushed the no-if branch 5 times, most recently from 0d79e98 to d0a691c Compare July 17, 2019 10:30
Comment thread src/rules/no-if.js Outdated
@SimenB SimenB merged commit 28bd1dc into jest-community:master Jul 17, 2019
@cartogram cartogram deleted the no-if branch July 17, 2019 13:04
@SimenB
Copy link
Copy Markdown
Member

SimenB commented Jul 17, 2019

🎉 This PR is included in version 22.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants