Fix time and date tests in Time.test.js
#522
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that the current test "should render date and time correctly" is not actually testing that the date and time are formatted correctly. It's just testing that the input and output are the same because the expected values in
Time.test.js
are specified the same way as inTime.vue
:So the tests are basically like this:
Or basically like
expect(foo()).toBe(foo())
.Testing that the input is the same as the output doesn't give any confidence/certainty that the values are formatted correctly.
Plus what if
today.toLocaleTimeString(/* ... */)
returnedundefined
for some reason? Then the test would be basically this:That's not quite what we want to test, right? 🙂
In this PR I'm explicitly defining that the expected values are
'01:23 PM'
and'March 10, 2020'
. This way the tests will actually fail if the time and date are not correctly formatted.I also removed an unnecessary line from
Time.vue
.