I have a greeting component that updates the time of day. Depending on the time of day the greeting will print
- Good Morning, Jane
- Good Afternoon, Jane
- Good Evening, Jane
I have function called getTimeOfDay
and test that this function is working. If you're interested view my tests here.
In my component I have a timer that checks every minute to see if the time of day message should update.
const [date, setDate] = useState(new Date())
const timeOfDay = getTimeOfDay(date)
useEffect(() => {
const timer = setInterval(() => {
setDate(new Date())
}, 60000)
return () => {
clearInterval(timer)
}
}, [])
I have been going back and forth on whether to test that this message changes correctly as the time passes. I know that testing implementation details is bad practice and was not sure if this was an implementation detail or a feature that should be tested.
If this is something I should test, I can't seem to easily implement a timer in jest that checks the message and then speeds up the timer 8 hours. What are your thoughts?