Files
classroomio/apps/dashboard/src/lib/utils/functions/date.spec.ts
T
Toyin MuhammedandRotimi Best 6d689ede45 feat: unit tests for utils (#92)
* init

* get unit test working for course.ts file

* added some other tests

* tests halfway + change config to accomodate js files

* utility functions tests done

* fix: config file + miscellaneous fixes

* fix: prepare script

* fix lock file

---------

Co-authored-by: Rotimi Best <[email protected]>
2023-12-20 14:28:40 +03:00

37 lines
1.3 KiB
TypeScript

import { calDateDiff, getGreeting } from './date';
describe('calDateDiff', () => {
test('should return the correct time difference when the input date is in the past', () => {
const inputDate = new Date('2022-01-01');
const expectedOutput = '2 years ago';
const result = calDateDiff(inputDate);
expect(result).toBe(expectedOutput);
});
test('should return the correct time difference when the input date is a number', () => {
const inputDate = new Date(1640995200000); // January 1, 2022
const expectedOutput = '2 years ago';
const result = calDateDiff(inputDate);
expect(result).toBe(expectedOutput);
});
});
describe('getGreeting', () => {
test("should return 'Good Morning' when the current time is before 12pm", () => {
jest.useFakeTimers().setSystemTime(new Date('2023-12-10T00:21:01.691Z'));
expect(getGreeting()).toBe('Good Morning');
});
test("should return 'Good Afternoon' when the current time is after 12pm", () => {
jest.useFakeTimers().setSystemTime(new Date('2023-12-10T14:21:01.691Z'));
expect(getGreeting()).toBe('Good Afternoon');
});
test("should return 'Good Evening' when the current time is after 6pm", () => {
jest.useFakeTimers().setSystemTime(new Date('2023-12-10T19:21:01.691Z'));
expect(getGreeting()).toBe('Good Evening');
});
});