3 ms·
Personally I see this a lot and I'm not a fan: it('should work', () => { inputOutputPairs.forEach(([input, output]) => { expect(testedFunction(inpu
by anonytrary 5y ago
Personally I see this a lot and I'm not a fan:
it('should work', () => {
inputOutputPairs.forEach(([input, output]) => {
expect(testedFunction(input)).equals(output);
})
})
Tests are way more useful when they are written with the intent of acting as documentation. If I had to give this test a grade (from F- to A+), it would get a D+. It catches regressions, yet does an absolutely horrid job of explaining the intent behind testedFunction.
- ramses0 5y agocases = [ { in: 1, arg: 2, expected: 3, message: "base case" }, { in: 2, arg: -2, expected: 0, message: "negative numbers" }, ... ] for ( c in cases ) { actual = obj.do( c.in, c.arg ) assert( actual == c.expected, c.message ) } see: http://fit.c2.com/ http://fit.c2.com/ ... table-based testing, "cases" and "drivers"