1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export type TestResult<T, TS = undefined> = TestResultPassed<T, TS> | TestResultFailed;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export declare function passTest<T>(value: T): TestResultPassed<T, undefined>;
|
12 |
|
13 |
|
14 |
|
15 | export declare function passTestVoid(): TestResultPassed<any, undefined>;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export declare function passTestWithSideData<T, S>(value: T, sideData: S): TestResultPassed<T, S>;
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export declare function passTestVoidWithSideData<TS>(sideData: TS): TestResultPassed<any, TS>;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | export declare function failTest(message: string): TestResultFailed;
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | export declare class TestResultPassed<T, TS> {
|
38 | protected readonly value: T;
|
39 | protected readonly sideData: TS;
|
40 | constructor(passValue: T, sideData: TS);
|
41 | /**
|
42 | * Check if the test has passed.
|
43 | * If true, it will contain a value.
|
44 | */
|
45 | isPassed(): this is TestResultPassed<T, TS>;
|
46 | /**
|
47 | * Check if the test has failed.
|
48 | * If true, it will contain a failure message.
|
49 | */
|
50 | isFailed(): this is TestResultFailed;
|
51 | /**
|
52 | * Get the value of the passed test, or undefined if the test failed.
|
53 | */
|
54 | get(): T;
|
55 | /**
|
56 | * Get the value of the passed test, or throw an error if the test failed.
|
57 | */
|
58 | getOrThrow(): T;
|
59 | /**
|
60 | * The side data that will be passed to run.
|
61 | */
|
62 | getSideData(): TS;
|
63 | /**
|
64 | * Get the failure message callback of the failed test, or undefined if the test passed.
|
65 | */
|
66 | getFailMessage(): undefined;
|
67 | /**
|
68 | * For passed tests, map the passed value to another value.
|
69 | * Failed tests will remain unchanged.
|
70 | *
|
71 | * This will not mutate the test result, and instead return a new test result.
|
72 | *
|
73 | * @param mapper A function that will transform the passed value.
|
74 | */
|
75 | map<T2>(mapper: (value: T, sideData: TS) => T2): TestResultPassed<T2, TS>;
|
76 | /**
|
77 | * For passed tests, asynchronously map the passed value to another value.
|
78 | * Failed tests will remain unchanged.
|
79 | *
|
80 | * This will not mutate the test result, and instead return a new test result.
|
81 | *
|
82 | * @param mapper A function that will transform the passed value.
|
83 | */
|
84 | mapAsync<T2>(mapper: (value: T, sideData: TS) => Promise<T2>): Promise<TestResultPassed<T2, TS>>;
|
85 | }
|
86 | /**
|
87 | * A failed test result.
|
88 | * This should not be constructed manually.
|
89 | * Instead, `testFail` should be used.
|
90 | */
|
91 | export declare class TestResultFailed {
|
92 | protected readonly failMessage: string;
|
93 | constructor(failMessage: string);
|
94 | /**
|
95 | * Check if the test has passed.
|
96 | * If true, it will contain a value.
|
97 | */
|
98 | isPassed(): this is TestResultPassed<any, any>;
|
99 | /**
|
100 | * Check if the test has failed.
|
101 | * If true, it will contain a failure message.
|
102 | */
|
103 | isFailed(): this is TestResultFailed;
|
104 | /**
|
105 | * Get the value of the passed test, or undefined if the test failed.
|
106 | */
|
107 | get(): undefined;
|
108 | /**
|
109 | * Get the value of the passed test, or throw an error if the test failed.
|
110 | */
|
111 | getOrThrow(): never;
|
112 | /**
|
113 | * The side data that will be passed to run.
|
114 | */
|
115 | getSideData(): never;
|
116 | /**
|
117 | * Get the failure message callback of the failed test, or undefined if the test passed.
|
118 | */
|
119 | getFailMessage(): string;
|
120 | /**
|
121 | * For passed tests, map the passed value to another value.
|
122 | * Failed tests will remain unchanged.
|
123 | *
|
124 | * This will not mutate the test result, and instead return a new test result.
|
125 | */
|
126 | map(): TestResultFailed;
|
127 | /**
|
128 | * For passed tests, asynchronously map the passed value to another value.
|
129 | * Failed tests will remain unchanged.
|
130 | *
|
131 | * This will not mutate the test result, and instead return a new test result.
|
132 | */
|
133 | mapAsync(): Promise<TestResultFailed>;
|
134 | }
|