Skip to content
New issue

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

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

Already on GitHub? # to your account

Missing expect assertions call #43

Merged

Conversation

tushardhole
Copy link
Contributor

Adding new lint rule which validates,

Every test to have expect.assertions({number of assertions}) as first line
OR
Every test to have expect.hasAssertions() as first line

@tushardhole
Copy link
Contributor Author

Looking for someone to help me understand how to solve below CI issues,
⧗ input: Enhance the missing_expect_assertions rule to,
✖ message may not be empty [subject-empty]
✖ type may not be empty [type-empty]
⚠ body must have leading blank line [body-leading-blank]
✖ found 2 problems, 1 warnings
⧗ input: Enhance missing expect assertions call rule to report error when expect.assertions() call is present but the argument provided is not a number.
✖ header must not be longer than 72 characters [header-max-length]
✖ message may not be empty [subject-empty]
✖ type may not be empty [type-empty]
✖ found 3 problems, 0 warnings

I am not able to figure out what is subject, header,body etc.

cc: @SimenB

@SimenB
Copy link
Member

SimenB commented Jan 5, 2018

It's yelling at you for not having semantic commits. See http://karma-runner.github.io/2.0/dev/git-commit-msg.html

@tushardhole
Copy link
Contributor Author

@SimenB Thanks for the help 👍

I will follow those conventions and verify it locally before pushing.

I am thinking to amend the commits on my branch and then do force push. Will that work or I am required to create a new PR.

@SimenB
Copy link
Member

SimenB commented Jan 5, 2018

Will that work or I am required to create a new PR.

Amending in this PR would be the best! 🙂

@giodamelio
Copy link

Not sure about the name, seems like prefer-expect-assertions would be more consistent with existing rules.


const ruleTester = new RuleTester();
const expectedMsg =
'Every test should have expect.assertions({number of assertions}) OR expect.hasAssertions() as first expression';

Choose a reason for hiding this comment

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

I think this might read better as

Every test should have either `expect.assertions(<number of assertions>)` or `expect.hasAssertions()` as it's first expression

if (isTestOrItFunction(node)) {
if (!isFirstLineExprStmt(node)) {
reportMsg(context, node);
return;

Choose a reason for hiding this comment

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

I think this return statement is unnecessary?

Intial code for missing_expect_assertions_call rule
Report error when expect.assertions() call is present but the argument provided is not a number
Rule will not report any error, if expect.hasAssertions() call is present. After this change, either expect.hasAssertions() or expect.assertions({number of assertions}) is required to pass the rule
Rename missing-expect-assertions-call to prefer-expect-assertions
@tushardhole tushardhole force-pushed the missing_expect_assertions_call branch from e8aefb1 to 2f4bc72 Compare January 8, 2018 11:44
@tushardhole
Copy link
Contributor Author

@giodamelio Thank for your feedback. I have renamed rule to prefer-expect-assertions and updated rule message.

@SimenB All CI checks are green. Thank you for your help! 🙂

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.

This is looking good!

Could you ensure 100% test coverage for the new rule?

Lines 13,47,55 are not covered (run yarn test --coverage to see)

(Also make sure to pull, I pushed a tiny bit to your branch 🙂 )

@tushardhole
Copy link
Contributor Author

@SimenB added the missing coverage.

@SimenB SimenB merged commit 4effb3c into jest-community:master Jan 9, 2018
@SimenB
Copy link
Member

SimenB commented Jan 9, 2018

Thanks! Released as 21.6.0

@SimenB
Copy link
Member

SimenB commented Jan 9, 2018

@tushardhole we forgot to update the README 😱 Mind sending a PR for that? 🙂

@tushardhole
Copy link
Contributor Author

@SimenB I would create an PR for README

@SimenB
Copy link
Member

SimenB commented Jan 9, 2018

Docs published in 21.6.1

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants