-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathdate.test.mjs
More file actions
40 lines (31 loc) · 1.33 KB
/
date.test.mjs
File metadata and controls
40 lines (31 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { dateIsBetween } from '#site/util/date';
describe('dateIsBetween', () => {
it('should return true when the current date is between start and end dates', () => {
const startDate = '2022-01-01T00:00:00.000Z';
const endDate = '2069-01-01T00:00:00.000Z';
assert.ok(dateIsBetween(startDate, endDate));
});
it('should return false when the current date is not between start and end dates', () => {
const startDate = '2010-01-01T00:00:00.000Z';
const endDate = '2020-01-01T00:00:00.000Z';
assert.ok(!dateIsBetween(startDate, endDate));
});
it('should throw an error when either start or end date is invalid', () => {
const invalidStartDate = 'Invalid Start Date';
const validEndDate = '2024-01-01T00:00:00.000Z';
assert.throws(
() => dateIsBetween(invalidStartDate, validEndDate),
/dateIsBetween got called with invalid dates/
);
});
it('should return true if now is between startDate and endDate', () => {
const start = new Date(Date.now() - 1000).toISOString();
const end = new Date(Date.now() + 1000).toISOString();
assert.ok(dateIsBetween(start, end));
});
it('should throw an error if dates are invalid', () => {
assert.throws(() => dateIsBetween('invalid', 'invalid'));
});
});