How can I run code before and after each it block?

describe('the counter effect', () => {
  let counter = 0
  beforeEach(() => counter++)
  afterEach(() => counter = 0)
  it('should display one', () => expect(counter).toBe(1))
  it('should still display one', () => expect(counter).toBe(1))
})

Last updated

Was this helpful?