The Problem:
Recently, while reviewing our existing test codebase, I've noticed a dangerous kind of typo/mistake when expect()
was used without the "matching" part:
expect(page.filters.fromDateLabel.getText(), "After");
I'm pretty sure toEqual()
was meant to be used here:
expect(page.filters.fromDateLabel.getText()).toEqual("After");
The problem with this is that jasmine
would not fail the expectation in this case (well, obviously because nothing was actually expected). And this gets us to a more serious problem - nothing was actually tested in a test case - it was passing with no expectations made. We were getting a false sense of what was tested.
The Question:
I want to catch these mistakes as fast as possible. How do you think I should handle the problem?
Thoughts:
- somehow fail a test case if there was no expectations made in it (not sure if
jasmine
has anything like this built-in) - "patch" the
expect()
and issue a warning/raise an error if nothing was called on the "expect" part - use static code analysis - define a custom
eslint
rule
Aucun commentaire:
Enregistrer un commentaire