jest-circus-allure-environment icon indicating copy to clipboard operation
jest-circus-allure-environment copied to clipboard

Exception raised within BeforeEach will be append to all tests within same suite

Open xuanzhaopeng opened this issue 3 years ago • 0 comments

In a nutshell, the main problem is that hook is not linked to test, but hook link to suite.

For BeforeAll , it's correct because beforeAll is executed one time for whole suite

but for beforeEach, it's incorrect, it should link to test, instead of suite

Example code:

describe('my suite', () => {
    let i = 0

    beforeEach(() => {
        if(i == 1) {
            i++;
            throw new Error('before each exception')
        }
        i++;
    })
    
    it('my test', () => {
        expect(1+1).toBe(3)
    })

    it('my test2', () => {
        expect(1+1).toBe(2)
    })

    it('my test3', () => {
        expect(1+1).toBe(2)
    })
})

xuanzhaopeng avatar Aug 06 '21 22:08 xuanzhaopeng