-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
35 lines (29 loc) · 928 Bytes
/
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
import { type Assertion, describe, expect, it } from 'vitest';
import { getYearDays } from './index';
const expectFunction = (year?: unknown): Assertion => expect(getYearDays(year as number));
const testFunction = (year: number, expected: number) => {
expectFunction(year).toBe(expected);
};
describe('Leap Year', () => {
it.each([
[2023, 384],
[2025, 384],
])('%i -> %i', testFunction);
});
describe('Non-leap Year', () => {
it.each([
[2024, 354],
[2026, 354],
])('%i -> %i', testFunction);
});
describe('Exception Case', () => {
it('return -1 if the given year is invalid', () => {
expectFunction().toBe(-1);
expectFunction(null).toBe(-1);
expectFunction(Number.NaN).toBe(-1);
});
it('return -1 if the given year is out of boundary', () => {
expectFunction(1899).toBe(-1);
expectFunction(2101).toBe(-1);
});
});