Add the following function to src/Appointment.js that converts a Unix timestamp (which we get from the return value from setHours) into a time of day. It doesn't matter where in the file you put it; I usually like to define constants before I use them, so this would go at the top of the file:
This uses the destructuring assignment and template literals, which are both space-saving features that you should start using if they aren't already part of your toolbox.
TDD can help us to overcome the fear of using complicated language features. If we're ever unsure what production code does, we can simply look at the tests to tell us.
Use the previous function to update AppointmentsDayView, as follows:
PASS test/Appointment.test.js Appointment ? renders the customer first name (19ms) ? renders another customer first name (2ms) AppointmentsDayView ? renders a div with the right id (7ms) ? renders multiple appointments in an ol element (13ms) ? renders each appointment in an li (4ms)
This is a great chance to refactor. Both of ourAppointmentsDayViewtests use the same datasets. These can be lifted out into the describe scope, the same way we did with customer in theAppointmenttests.This time, however, they can remain asconstdeclarations as they never change.
To do that, move the todayandappointmentsdefinitions from one of the tests to the top of the describe block, above beforeEach. Then, delete the definitions from both tests.