Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

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

Open
xuanzhaopeng opened this issue Aug 6, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@xuanzhaopeng
Copy link

xuanzhaopeng commented Aug 6, 2021

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 xuanzhaopeng added the bug Something isn't working label Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant