I know that having shared state between tests is bad practice and should be avoided if possible. But I'm just curious how are these two constructs below different in Jest:
describe-block
describe('test suite', () => { const theAnswer = 42; test('a test case', () => { expect(theAnswer + 1).toEqual(43); }); test('another test case', () => { expect(theAnswer + -1).toEqual(41); }); }); vs.
beforeAll
describe('test suite with beforeAll', () => { let theAnswer; beforeAll(() => { theAnswer = 42; }); test('a test case', () => { expect(theAnswer + 1).toEqual(43); }); test('another test case', () => { expect(theAnswer + -1).toEqual(41); }); }); What's the significance of using beforeAll if we can directly declare a shared variable/state in the describe block?
theAnswer?