Skip to content

AfterEach does not run when test fails #42

@Bareus

Description

@Bareus

It seems like afterEach hooks do not run when a test fails in mocha.parallel. In standard mocha an afterEach hook runs even when a test fails.

Here an example:

parallel("Test Suit Collection", function() {
    let tmp = 0;
    afterEach("cleanUp", function() {
        console.log(tmp);
    });

    it("test 1", async function() {
        await sleep(1000);
        expect(true).to.be.false;
        tmp = 1;
    });

    it("test 2", async function() {
        await sleep(1000);
        expect(true).to.be.true;
        tmp = 2;
    });
});

Output:

Test Suit Collection
2
    1) test 1
    √ test 2 (1003ms)

As you can see the afterEach for test 1 never run, while it runs for test 2. Luckily I can still work with the after hook so this is not a big problem for me, but it would be nice if you can fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions