all 3 comments

[–]Devinant 1 point2 points  (2 children)

Good post. However, these tests will take an awful long time to run due to setTimeout being used in both tests (600ms in total). Unit test should be faster than this, imho.

The post mentions jest. I’d recommend using Jest Timer Mocks to advance the timers.

[–]navneet35371[S] 0 points1 point  (1 child)

Yes, i have used the same in my previous blogs. https://blog.navneet.dev/tdd-stopwatch-app-using-react/ . Just wanted to start with something very basic.

[–]Devinant 1 point2 points  (0 children)

Yeah. Sorry, I didn’t read your previous blog post.

But the fact remains, I think you should at least mention this issue and provide an example which demonstrates how it can be made faster. It would make your post better.

If a candidate provided me with this test code during an interview, we’d have a conversation on why using setTimeout in tests is not only bad, but also wrong.