|
|
|
|
|
by j1elo
935 days ago
|
|
Agree with both. Recently, youtube channel ThePrimeagen was talking about this, and coincidentally put up a very silly but clarifying example, luckily he also posted to Twitter so here it is just for fun [1]: function foo(num: number): number {
const a = [1];
let sum = 0;
for (let i = 0; i < num; ++i) {
sum += a[i];
}
return sum;
}
test("foo", () => {
expect(foo(1)).toEqual(1);
});
100% test coverage
100% still bugged af
[1]: https://nitter.net/ThePrimeagen/status/1639250735505235975 |
|
That isn't necessarily a problem. The primary purpose of your tests is to document the API. As long as someone is able to determine what the function is for, and how it is meant to be used, along with other intents and information the author needs to convey to users of the API, the goal is met.
However, I don't see how the given test actually helps document anything, so it is not a good example in the slightest. 100% coverage doesn't indicate that you did a good job, but if there are code paths not touched then you know you screwed up your documenting big time.