1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00
p61-project/utils/__tests__/dates.test.ts

56 lines
1.4 KiB
TypeScript

import { getISODate, getWeekNumber } from "../dates"
describe("utils/dates", () => {
describe("getISODate", () => {
it("should return the correct date in ISO format (e.g: 2012-05-23)", () => {
// Arrange - Given
const date = new Date("2012-05-23")
// Act - When
const result = getISODate(date)
// Assert - Then
const expected = "2012-05-23"
expect(result).toEqual(expected)
})
})
describe("getWeekNumber", () => {
it("should return the correct week number for a given date (e.g: 2020-01-01)", () => {
// Arrange - Given
const date = new Date("2020-01-01")
// Act - When
const result = getWeekNumber(date)
// Assert - Then
const expected = 1
expect(result).toEqual(expected)
})
it("should return the correct week number for a given date (e.g: 2020-01-08)", () => {
// Arrange - Given
const date = new Date("2020-01-08")
// Act - When
const result = getWeekNumber(date)
// Assert - Then
const expected = 2
expect(result).toEqual(expected)
})
it("should return the correct week number for a given date (e.g: 2020-12-31)", () => {
// Arrange - Given
const date = new Date("2020-12-31")
// Act - When
const result = getWeekNumber(date)
// Assert - Then
const expected = 53
expect(result).toEqual(expected)
})
})
})