Skip to content

Commit d1f8fec

Browse files
authored
fix: use static base date for timeline tests (coder#5460)
It was returning "yesterday" since today is Sunday ;p
1 parent 88d3496 commit d1f8fec

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

site/src/components/Timeline/Timeline.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { createDisplayDate } from "./TimelineDateRow"
22

33
describe("createDisplayDate", () => {
44
it("returns correctly for Saturdays", () => {
5-
const now = new Date()
5+
const now = new Date(2020, 1, 7)
66
const date = new Date(
77
now.getFullYear(),
88
now.getMonth(),
99
// Previous Saturday, from now.
1010
now.getDate() - now.getDay() - 1,
1111
)
12-
expect(createDisplayDate(date)).toEqual("last Saturday")
12+
expect(createDisplayDate(date, now)).toEqual("last Saturday")
1313
})
1414
})

site/src/components/Timeline/TimelineDateRow.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export interface TimelineDateRow {
1010

1111
// We only want the message related to the date since the time is displayed
1212
// inside of the build row
13-
export const createDisplayDate = (date: Date): string =>
14-
formatRelative(date, new Date()).split(" at ")[0]
13+
export const createDisplayDate = (date: Date, base = new Date()): string =>
14+
formatRelative(date, base).split(" at ")[0]
1515

1616
export const TimelineDateRow: FC<TimelineDateRow> = ({ date }) => {
1717
const styles = useStyles()

0 commit comments

Comments
 (0)