Loading
Build a TypeScript Project From Scratch Tutorial (19 exercises)
Lesson

Fix Same Day Bug

In this lesson, you will fix a bug related to the same-day login logic.

Resources

The following resources provide more information for this lesson:

Transcript

Instructor: [0:00] Oh, no. It looks like our library has a bug. Check this out. When you refresh the page, it continues incrementing, even though we're logging in the same day, and it should be returning, none, and not incrementing. Let's fix that. Inside of your test directory, create a new file called, lib.test.ts and paste in this code. Then run pnpm test. We'll see it's actually returning increment when it should be returning none.
[0:24] I believe the function is where the bug is inside of our differenceInDays. Here, we're going to try out a different differenceInDays function, called diff, which I've got from Stack Overflow. It's still failing. What we'll do now is come in here, change this to diff, and for currentDate we'll do toDateString(). It's a function. We'll delete this and save and see.

[0:46] Now that it's passing, commit that, bump your package Json, commit that, and push it up. Once that's published, go back to your sandbox. Hit this icon to update to latest. Refresh the page and actually what we'll do is inspect, go to application in here, and will delete this. Then refresh again. We'll see that it's in one day. If we refresh again, it stays at one day. Now the bug is fixed.