generated from brianrodri/obsidian-preact-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluxon-utils.test.ts
44 lines (37 loc) · 2.03 KB
/
luxon-utils.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
import { entriesIn } from "lodash";
import { DateTime, DateTimeMaybeValid, Duration, DurationMaybeValid, Interval, IntervalMaybeValid } from "luxon";
import { describe, expect, it } from "vitest";
import { assertIntervalsDoNotIntersect, assertLuxonValidity } from "../luxon-utils";
import { WITH_OVERLAPPING_INTERVALS, WITHOUT_OVERLAPPING_INTERVALS } from "./luxon-utils.test.const";
describe(`${assertLuxonValidity.name}`, () => {
const reason = "user-provided reason";
const explanation = "user-provided explanation";
describe.each(["user-provided message", undefined])("with message=%j", (message) => {
it.each([
DateTime.fromISO("2025-03-05"),
Duration.fromDurationLike({ days: 1 }),
Interval.after(DateTime.now(), { days: 1 }),
])("should accept valid $constructor.name", (value) => {
expect(() => assertLuxonValidity(value, message)).not.toThrow();
});
it.each([
DateTime.invalid(reason, explanation) as DateTimeMaybeValid,
Duration.invalid(reason, explanation) as DurationMaybeValid,
Interval.invalid(reason, explanation) as IntervalMaybeValid,
])("should reject invalid $constructor.name", (value) => {
expect(() => assertLuxonValidity(value, message)).toThrowErrorMatchingSnapshot();
});
it("should reject undefined", () => {
expect(() => assertLuxonValidity(undefined, message)).toThrowErrorMatchingSnapshot();
});
});
});
describe(`${assertIntervalsDoNotIntersect.name}`, () => {
it.each(entriesIn(WITHOUT_OVERLAPPING_INTERVALS))("should accept %j", (_, intervals) => {
expect(() => assertIntervalsDoNotIntersect(intervals)).not.toThrow();
});
it.each(entriesIn(WITH_OVERLAPPING_INTERVALS))("should reject %j", (_, intervals) => {
// TODO: Want to use toThrowErrorMatchingSnapshot(), but the snapshot fails on CI due to different paths in the stack traces.
expect(() => assertIntervalsDoNotIntersect(intervals)).toThrowError();
});
});