I'm trying to get some logic to be called before and after each nested describe of a jasmine test suite I'm writing.
I have something like this right now:
describe('Outer describe', function () {
beforeEach(function () {
login();
someOtherFunc();
});
afterEach(function () {
logout();
});
describe('inner describe', function () {
it('spec A', function () {
expect(true).toBe(true);
});
it('spec B', function () {
expect(true).toBe(true);
});
});
});
I'm finding my functions in the beforeEach
and afterEach
are called for each it
inside my inner describe. I only want these to be called once for each inner describe I have in the outer one.
Is this possible?
beforeEach
in the top level describe will run the code before every test, including nested tests. I'm using vitest. You can test this withbeforeEach(() => console.error("HELLO"))
and read the output.