Note that if you're perfectly happy with the style of descriptions you used to write in Python, there is no reason to change that. Put the name of the tested block within the describe
, and put your description in it
. If it's clear for you, it doesn't matter what the designers of the test framework had in mind.
If you're for some reason unhappy with porting your style to JavaScript, then stick with it('should do this or that')
, and just below it
, include the complete description:
describe('the ruler', () => {
describe('after a double-click', () => {
it('should reflect the cursor position instead of assuming a (0, 0)', () => {
/**
* The edge case documented in CAP-621 happens when a user, instead of simply
* clicking once to position the first side of the ruler, and then click
* another time somewhere else to fix the ruler on the page, double-clicks on
* the page. The previous behavior was that the ruler was drawn from the cursor
* to the (0, 0) of the page. Instead, a double-click should be treated as if
* it was a simple click, letting the user to position the other side of the
* ruler with another click or double-click.
*/
...
});
});
});
When reading a test, for instance in the context where a change in the code broke it, either you'll understand its purpose just by looking at its name, or you'll read the long comment. This style may even be preferable to having only the long description: if the test is recent or if it concerns a part you were working on recently, chances are, you won't need the whole description, and having a short name would save you time.
Best Answer
There a couple of technique you can use here:
1) Replace the random number generator with one that produces canned values, and check that the expected values are gotten
2) Run the algorithm a whole lots of times, and sum up the results
The idea here is that if you run the algorithm enough times the law of large numbers will make the totals similar the theoretically expected ones. Then you check that.