Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 17, 2019
Merged

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

merged 3 commits into from
Jul 17, 2019

Conversation

cartogram
Copy link
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
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 🙂

src/rules/no-if.js Outdated Show resolved Hide resolved
@cartogram cartogram force-pushed the no-if branch 5 times, most recently from 0d79e98 to d0a691c Compare July 17, 2019 10:30
src/rules/no-if.js Outdated Show resolved Hide resolved
@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
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