The Scenario:
In our extensive test codebase utilizing Protractor+Jasmine, we are encountering an issue where some test/spec files contain multiple describe blocks. This has caused issues during debugging, as using fdescribe
/fit
to run tests individually or in batches can inadvertently skip portions of the tests due to overlooked additional describe blocks at the bottom of the file.
This situation resembles the "one assertion per test" principle, aiming to maintain a tidy and concise test codebase.
The Query:
We are exploring methods to restrict the presence of more than one describe block per file. Our initial thoughts revolve around employing static code analysis tools like ESLint; however, we welcome alternative suggestions for addressing this issue effectively.
Instances:
An example illustrating a violation:
describe("Test 1", function () {
it("should do something", function () {
expect(true).toBe(true);
});
});
describe("Test 2", function () {
it("should do something else", function () {
expect(false).toBe(false);
});
});
If a single describe block contains nested describes, it should not be flagged as a violation. For instance, the following structure is permissible:
describe("Test 1", function () {
it("should do something", function () {
expect(true).toBe(true);
});
describe("Test 2", function () {
it("should do something else", function () {
expect(false).toBe(false);
});
});
});