Loading
Current section: Date and time 5 exercises
lesson

Intro to Date and time

Loading lesson

Transcript

00:00 Date and time are one of the trickiest variables your code may have. Well, because they're constantly changing. If I had a simple function that constructs a new date and returns it, it would return a different date every time it's being called. But I would still have to specify just a single expected date in the test for that function. I wouldn't want it to pass on Monday and fail on Wednesday.

00:19 That would be a terrible test. And duration is not the only variable here. You and your colleague may have dramatically different test results if you happen to work in different time zones. So in order to eliminate a side effect of constructing a new date, you have to freeze time. And mocking comes in handy here.

00:36 Although you can technically spy on the date constructor and mock its implementation, the same way you learned how to do in the previous exercise, there are much more convenient ways for you to work with date and time in VTEST. And it's not only date and time. It's also timers and intervals, as well as things scheduled for the next tick of the event loop.

00:53 In this exercise, you will learn how to mock and test time-related functionality. Let's begin.