Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.8 KB
Raw Blame
function currentFixtureTestName(): string | undefined {
    const state = (globalThis as typeof globalThis & { expect: jest.Expect }).expect.getState()
    return typeof state.currentTestName === 'string' ? state.currentTestName : undefined
}

describe('jest quarantine runtime fixture', () => {
    beforeAll(() => {
        if (currentFixtureTestName() === undefined) {
            throw new Error('quarantined beforeAll failure')
        }
    })

    beforeEach(() => {
        if (currentFixtureTestName()?.includes('tolerates beforeEach failure')) {
            throw new Error('quarantined beforeEach failure')
        }
    })

    afterEach(() => {
        if (currentFixtureTestName()?.includes('tolerates afterEach failure')) {
            throw new Error('quarantined afterEach failure')
        }
    })

    test('tolerates body failure', () => {
        throw new Error('quarantined body failure')
    })

    test('tolerates async rejection', async () => {
        throw new Error('quarantined async failure')
    })

    test.each([1])('tolerates each row %s', () => {
        throw new Error('quarantined each row failure')
    })

    test.each([2])('keeps unrelated done row %s', (value, done) => {
        expect(value).toBe(2)
        done()
    })

    test.each([3])('tolerates each done row %s', (_value, done) => {
        done(new Error('quarantined each done row failure'))
    })

    describe.each(['A'])('parameterized describe %s', () => {
        test('tolerates nested failure', () => {
            throw new Error('quarantined parameterized describe failure')
        })
    })

    test('tolerates beforeEach failure', () => {
        expect(true).toBe(true)
    })

    test('tolerates afterEach failure', () => {
        expect(true).toBe(true)
    })

    test('skips body', () => {
        throw new Error('skipped body should not run')
    })
})