Skip to content

Commit ed4dcba

Browse files
committed
Add comments for assert and test interface definitions
1 parent 1d9f176 commit ed4dcba

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

index.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,61 @@ export interface SnapshotOptions {
1717
id?: string;
1818
}
1919

20+
// When an assert fail, the message string will be shown in the error
2021
export interface Assertions {
22+
// Assert that actual is deep equal to expected
2123
deepEqual<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
24+
// Failing assertion
2225
fail(message?: string): void;
26+
// Assert that actual is equal to false
2327
false(actual: any, message?: string): void;
28+
// Assert that actual is falsy (false, 0, '', "", null, undefined, NaN)
2429
falsy(actual: any, message?: string): void;
30+
// Assert that error is falsy
2531
ifError(error: any, message?: string): void;
32+
// Assert that actual is equal to expected (use deepEqual for objects/arrays)
2633
is<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
34+
// Assert that actual is not equal to expected (use notDeepEqual for objects/arrays)
2735
not<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
36+
// Assert that actual is not deep equal to expected
2837
notDeepEqual<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
38+
// Assert that string does not follow the regex pattern
2939
notRegex(string: string, regex: RegExp, message?: string): void;
40+
// Assert that a function that never returns does not throw an error
3041
notThrows(value: () => never, message?: string): void;
42+
// Assert that a function that returns an observable does not throw an error
3143
notThrows(value: () => ObservableLike, message?: string): Promise<void>;
44+
// Assert that a function that returns a promise does not throw an error
3245
notThrows(value: () => PromiseLike<any>, message?: string): Promise<void>;
46+
// Assert that a function that returns any value does not throw an error
3347
notThrows(value: () => any, message?: string): void;
48+
// Assert that an observable does not throw an error
3449
notThrows(value: ObservableLike, message?: string): Promise<void>;
50+
// Assert that a promise does not throw an error
3551
notThrows(value: PromiseLike<any>, message?: string): Promise<void>;
52+
// Passing assertion
3653
pass(message?: string): void;
54+
// Assert that string follows the regex pattern
3755
regex(string: string, regex: RegExp, message?: string): void;
56+
// Assert that expected matches a snapshot
3857
snapshot(expected: any, message?: string): void;
58+
// Assert that expected matches a snapshot with option `id`
3959
snapshot(expected: any, options: SnapshotOptions, message?: string): void;
60+
// Assert that a function that never returns throws an error
4061
throws(value: () => never, error?: ThrowsErrorValidator, message?: string): any;
62+
// Assert that a function that returns an observable throws an error
4163
throws(value: () => ObservableLike, error?: ThrowsErrorValidator, message?: string): Promise<any>;
64+
// Assert that a function that returns a promise throws an error
4265
throws(value: () => PromiseLike<any>, error?: ThrowsErrorValidator, message?: string): Promise<any>;
66+
// Assert that a function that returns any value throws an error
4367
throws(value: () => any, error?: ThrowsErrorValidator, message?: string): any;
68+
// Assert that an observable throws an error
4469
throws(value: ObservableLike, error?: ThrowsErrorValidator, message?: string): Promise<any>;
70+
// Assert that a promise throws an error
4571
throws(value: PromiseLike<any>, error?: ThrowsErrorValidator, message?: string): Promise<any>;
72+
// Assert that actual is equal to true
4673
true(actual: any, message?: string): void;
74+
// Assert that actual is truthy ('0', 'false', [], {}, function() {}, etc.)
4775
truthy(actual: any, message?: string): void;
4876
}
4977

@@ -78,15 +106,25 @@ export interface TestInterface<Context = {}> {
78106
(title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
79107
(macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
80108

109+
// Test hook that runs after all tests are done
81110
after: AfterInterface<Context>;
111+
// Test hook that runs after each test is done
82112
afterEach: AfterInterface<Context>;
113+
// Test hook that runs before all test starts
83114
before: BeforeInterface<Context>;
115+
// Test hook that runs before each test starts
84116
beforeEach: BeforeInterface<Context>;
117+
// Test modifier that enables callback support
85118
cb: CbInterface<Context>;
119+
// Test modifier to forcely fails a test
86120
failing: FailingInterface<Context>;
121+
// Test modifier to run this test only
87122
only: OnlyInterface<Context>;
123+
// Test modifier to run test with serial tag first serially
88124
serial: SerialInterface<Context>;
125+
// Test modifier to skip tagged tests
89126
skip: SkipInterface<Context>;
127+
// Test modifier for todo tests
90128
todo: TodoDeclaration;
91129
}
92130

index.js.flow

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,57 @@ export interface SnapshotOptions {
2222
id?: string;
2323
}
2424

25+
// When an assert fail, the message string will be shown in the error
2526
export interface Assertions {
27+
// Assert that actual is deep equal to expected
2628
deepEqual(actual: any, expected: any, message?: string): void;
29+
// Failing assertion
2730
fail(message?: string): void;
31+
// Assert that actual is equal to false
2832
false(actual: any, message?: string): void;
33+
// Assert that actual is falsy (false, 0, '', "", null, undefined, NaN)
2934
falsy(actual: any, message?: string): void;
35+
// Assert that error is falsy
3036
ifError(error: any, message?: string): void;
37+
// Assert that actual is equal to expected (use deepEqual for objects/arrays)
3138
is(actual: any, expected: any, message?: string): void;
39+
// Assert that actual is not equal to expected (use notDeepEqual for objects/arrays)
3240
not(actual: any, expected: any, message?: string): void;
41+
// Assert that actual is not deep equal to expected
3342
notDeepEqual(actual: any, expected: any, message?: string): void;
43+
// Assert that string does not follow the regex pattern
3444
notRegex(string: string, regex: RegExp, message?: string): void;
45+
// Assert that a function that returns an observable does not throw an error
3546
notThrows(value: () => ObservableLike, message?: string): Promise<void>;
47+
// Assert that a function that returns a promise does not throw an error
3648
notThrows(value: () => PromiseLike<any>, message?: string): Promise<void>;
49+
// Assert that a function that returns any value does not throw an error
3750
notThrows(value: () => any, message?: string): void;
51+
// Assert that an observable does not throw an error
3852
notThrows(value: ObservableLike, message?: string): Promise<void>;
53+
// Assert that a promise does not throw an error
3954
notThrows(value: PromiseLike<any>, message?: string): Promise<void>;
55+
// Passing assertion
4056
pass(message?: string): void;
57+
// Assert that string follows the regex pattern
4158
regex(string: string, regex: RegExp, message?: string): void;
59+
// Assert that expected matches a snapshot
4260
snapshot(expected: any, message?: string): void;
61+
// Assert that expected matches a snapshot with option `id`
4362
snapshot(expected: any, options: SnapshotOptions, message?: string): void;
63+
// Assert that a function that returns an observable throws an error
4464
throws(value: () => ObservableLike, error?: ThrowsErrorValidator, message?: string): Promise<any>;
65+
// Assert that a function that returns a promise throws an error
4566
throws(value: () => PromiseLike<any>, error?: ThrowsErrorValidator, message?: string): Promise<any>;
67+
// Assert that a function that returns any value throws an error
4668
throws(value: () => any, error?: ThrowsErrorValidator, message?: string): any;
69+
// Assert that an observable throws an error
4770
throws(value: ObservableLike, error?: ThrowsErrorValidator, message?: string): Promise<any>;
71+
// Assert that a promise throws an error
4872
throws(value: PromiseLike<any>, error?: ThrowsErrorValidator, message?: string): Promise<any>;
73+
// Assert that actual is equal to true
4974
true(actual: any, message?: string): void;
75+
// Assert that actual is truthy ('0', 'false', [], {}, function() {}, etc.)
5076
truthy(actual: any, message?: string): void;
5177
}
5278

@@ -81,15 +107,25 @@ export interface TestInterface<Context = {}> {
81107
(title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
82108
(macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void;
83109

110+
// Test hook that runs after all tests are done
84111
after: AfterInterface<Context>;
112+
// Test hook that runs after each test is done
85113
afterEach: AfterInterface<Context>;
114+
// Test hook that runs before all test starts
86115
before: BeforeInterface<Context>;
116+
// Test hook that runs before each test starts
87117
beforeEach: BeforeInterface<Context>;
118+
// Test modifier that enables callback support
88119
cb: CbInterface<Context>;
120+
// Test modifier to forcely fails a test
89121
failing: FailingInterface<Context>;
122+
// Test modifier to run this test only
90123
only: OnlyInterface<Context>;
124+
// Test modifier to run test with serial tag first serially
91125
serial: SerialInterface<Context>;
126+
// Test modifier to skip tagged tests
92127
skip: SkipInterface<Context>;
128+
// Test modifier for todo tests
93129
todo: TodoDeclaration;
94130
}
95131

0 commit comments

Comments
 (0)