Proposal: Make title not optional and having two tests with the same title should fail the tests
See original GitHub issueI’m proposing two breaking changes, that would aim users to have a better test suite (or at least better documented in a way)
Making the title of a test mandatory
I can barely see why there should not be one. I can only imagine the case where the file only has one test in a file whose name is self-explanatory, but even then, an additional title can’t hurt. In all other cases (like having multiple tests without a title), you’re having “undocumented” tests, which is not great for your test suite. I see having a mandatory title as a feature rather than an inconvenience. (And if we do, we should probably forbid ""
as the test title).
Having two tests with the same title should fail the tests
- having two tests in a file (or group, in the future) share the same title should fail the tests
- (should we implement groups) having two groups in a file or inside another group share the same title should fail the tests
The reasoning is like this: If I have two tests with the same title, I have probably copy-pasted a test without updating the title, or I have two tests that do not describe very well what they are testing. Enforcing different titles for every test should help have more descriptive tests. We already attempt to enforce that in the AVA ESLint plugin, but it would be done more effectively in the runner.
Should the title be kept optional, we would probably ignore tests without title, or accept at most one.
(I made the same proposal in an other test runner, and thought I’d propose it here too. Titles in that test runner are mandatory too by the way)
Let me know what you think 😃
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (11 by maintainers)
I’m a big 👍 on requiring unique test titles. I think that’s a great change.
I would also be ok with requiring a test title for multiple tests, but I kinda like the ability to not have a title when you only have one test though. I use this a lot in my tiny modules. Example. Although, I’m happy to be convinced otherwise.
I think both of these suggestions are valid and good improvements.
We actually had some trouble with duplicated test titles a while ago. It turned out that when we wrote our first test for a new react component. We always ended up calling it ‘Render to DOM’ by default. None really thought about it and it just happened out of habit.
Then at some point we where making a new component and our ‘Render to DOM’ test just kept on failing. It was a real simple test and we could not figure out what was wrong.
Turned out some other code had broken a previous ‘Render to DOM’ test in a different component and we just didn’t see that it wasn’t the one we where looking at…