Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.01 KB

no-assertions-in-hooks.md

File metadata and controls

54 lines (40 loc) · 1.01 KB

Disallow assertions in hooks

recommended-badge

Assertions should not be part of before/after hooks. The key of an assertion is to explicitly test something which should be obviously part of the test and not part of any hooks.

Rule Details

Examples of incorrect code for this rule:

beforeEach(() => {
    expect(true).to.be.true;
});

afterAll(() => {
    expect(true).to.be.true;
});

Examples of correct code for this rule:

describe('test suite', () => {
    beforeEach(() => {
        setUp();
    });

    afterEach(() => {
        cleanUp();
    });

    it('should assert something', () => {
        expect(true).to.equal(true);
    });
});

Options

The assertCommands array contains the assert function names to match on. This will override the defaults.

{
    "ui-testing/no-assertions-in-hooks": [
        "error",
        {
            "assertCommands": ["expect"]
        }
    ]
}