Pattern: Misplaced hook
Issue: -
While hooks can be placed anywhere in a test file, they are always executed in a specific order. Placing hooks between test cases makes the code flow harder to understand and can lead to confusion about execution order.
Example of incorrect code:
describe("suite", () => {
it("test one", () => {});
beforeEach(() => {
setup();
});
it("test two", () => {});
beforeAll(() => {
init();
});
});
Example of correct code:
describe("suite", () => {
beforeAll(() => {
init();
});
beforeEach(() => {
setup();
});
it("test one", () => {});
it("test two", () => {});
});