Skip to content

[expect-expect] Option to enforce the last statement of a test to be an assertion #1338

Open
@CreativeTechGuy

Description

@CreativeTechGuy

The expect-expect rule works great for identifying a test that doesn't have any assertions, but it doesn't work for identifying halfway-complete tests. Often more complex test cases (such as JSDOM tests) will have multiple assertions, usually before something has occurred to assert the base state is correct, then perform an action, and then assert that the values have changed as expected. I have found a few times where I'll be writing a test and get distracted halfway through and forget to finish the second half of the test. Code coverage looks good since all of the actions were performed, but the test was missing the critical assertions at the end.

In almost every test, there should be an assertion as the last statement. The only case where I can think of that not being true is when the assertions are inside of callback function, but that can be avoided by putting expect.assertions(number) as the last line.

Since it seems like a generally useful option which aligns with the spirit of this rule, I wanted to suggest this as a new feature.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions