Pattern: Test outside describe
Issue: -
Test cases and hooks should be contained within a top-level describe block to provide better organization and context for the test suite. This makes test output more readable and maintainable.
Example of incorrect code:
beforeEach(() => {
setup();
});
test("standalone test", () => {
expect(value).toBe(true);
});
describe("some tests", () => {});
afterAll(() => {
cleanup();
});
Example of correct code:
describe("feature", () => {
beforeEach(() => {
setup();
});
test("behavior", () => {
expect(value).toBe(true);
});
afterAll(() => {
cleanup();
});
});