GlobeTownDevs / stopwatch

Stopping your watches
0 stars 1 forks source link

done() in beforeEach for async #6

Closed tbtommyb closed 7 years ago

tbtommyb commented 7 years ago

So I'm not sure about this at all, but on lines 57-58 done() is called before the stopTimer() bit.

From this article, done() 'The done() call is made within the success() callback function to instruct jasmine that beforeEach() has terminated and it is now safe to continue with the it() function.' So I'm not sure if the stopTimer()bit is called and how it fits with the code in the other tests.

When you swap lines 57-58 around, the timer goes up to nearly 5 seconds. I think this is because beforeEach gets called once for each of the functions and so it adds up 2500ms twice. This means your last test fails because it expects a 2 (as Nick says in #3 ). However, this behaviour seems a bit more in line with how the code should work (because you never reset the timer) so I think you do need to swap l57-58.

You could add a call to resetTimer to the beforeEach bit so that your counter is starting from 0 for each test.

marisid commented 7 years ago

Thanks for that. Including resetTimer inside the beforeEach would still make our last test to fail because it resets immediately back to zero and cannot check the displayed time. Instead, we swapped the lines with done() ans stopTimer() around and adjusted our expectations accordingly.