-
-
Notifications
You must be signed in to change notification settings - Fork 696
/
isDateInRange.test.ts
45 lines (38 loc) · 1.29 KB
/
isDateInRange.test.ts
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
41
42
43
44
45
import { addDays } from 'date-fns';
import { DateRange } from 'index';
import { isDateInRange } from './isDateInRange';
const date = new Date();
describe('when range is missing the "from" date', () => {
const range: DateRange = { from: undefined };
const result = isDateInRange(date, range);
test('should return false', () => {
expect(result).toBe(false);
});
});
describe('when range is missing the "to" date', () => {
const result = isDateInRange(date, { from: date, to: undefined });
test('should return true', () => {
expect(result).toBe(true);
});
});
describe('when the range dates are the same as date', () => {
const range: DateRange = { from: date, to: date };
const result = isDateInRange(date, range);
test('should return true', () => {
expect(result).toBe(true);
});
});
describe('when the range dates are the same but not as date', () => {
const range: DateRange = { from: date, to: date };
const result = isDateInRange(addDays(date, 1), range);
test('should return false', () => {
expect(result).toBe(false);
});
});
describe('when the range is inverted', () => {
const range: DateRange = { from: addDays(date, 1), to: date };
const result = isDateInRange(date, range);
test('should return true', () => {
expect(result).toBe(true);
});
});