Skip to content

Commit 555e500

Browse files
committed
[draft] feat: assertions return booleans
1 parent d8b1e89 commit 555e500

File tree

3 files changed

+515
-417
lines changed

3 files changed

+515
-417
lines changed

index.d.ts

+128-42
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,68 @@ export type CommitDiscardOptions = {
3333
};
3434

3535
export interface Assertions {
36-
/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */
36+
/**
37+
* Assert that `actual` is
38+
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
39+
* returning Boolean indicating whether the assertion passes. Comes with
40+
* power-assert.
41+
*/
3742
assert: AssertAssertion;
3843

39-
/** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
44+
/**
45+
* Assert that `actual` is [deeply
46+
* equal](https://github.com/concordancejs/concordance#comparison-details) to
47+
* `expected`, returning Boolean indicating whether the assertion passes.
48+
*/
4049
deepEqual: DeepEqualAssertion;
4150

42-
/** Assert that `actual` is like `expected`. */
51+
/**
52+
* Assert that `value` is like `selector`, returning Boolean indicating
53+
* whether the assertion passes.
54+
*/
4355
like: LikeAssertion;
4456

45-
/** Fail the test. */
57+
/** Fail the test, always returning `false`. */
4658
fail: FailAssertion;
4759

48-
/** Assert that `actual` is strictly false. */
60+
/**
61+
* Assert that `actual` is strictly false, returning Boolean indicating
62+
* whether the assertion passes.
63+
*/
4964
false: FalseAssertion;
5065

51-
/** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
66+
/**
67+
* Assert that `actual` is
68+
* [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning
69+
* Boolean whether the assertion passes.
70+
*/
5271
falsy: FalsyAssertion;
5372

5473
/**
5574
* Assert that `actual` is [the same
56-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
75+
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
76+
* as `expected`, returning Boolean indicating whether the assertion passes.
5777
*/
5878
is: IsAssertion;
5979

6080
/**
6181
* Assert that `actual` is not [the same
62-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
82+
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
83+
* as `expected`, returning Boolean indicating whether the assertion passes.
6384
*/
6485
not: NotAssertion;
6586

66-
/** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
87+
/**
88+
* Assert that `actual` is not [deeply
89+
* equal](https://github.com/concordancejs/concordance#comparison-details) to
90+
* `expected`, returning Boolean indicating whether the assertion passes.
91+
*/
6792
notDeepEqual: NotDeepEqualAssertion;
6893

69-
/** Assert that `string` does not match the regular expression. */
94+
/**
95+
* Assert that `string` does not match the regular expression, returning
96+
* Boolean indicating whether the assertion passes.
97+
*/
7098
notRegex: NotRegexAssertion;
7199

72100
/** Assert that the function does not throw. */
@@ -75,10 +103,13 @@ export interface Assertions {
75103
/** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */
76104
notThrowsAsync: NotThrowsAsyncAssertion;
77105

78-
/** Count a passing assertion. */
106+
/** Count a passing assertion, always returning `true`. */
79107
pass: PassAssertion;
80108

81-
/** Assert that `string` matches the regular expression. */
109+
/**
110+
* Assert that `string` matches the regular expression, returning Boolean
111+
* indicating whether the assertion passes.
112+
*/
82113
regex: RegexAssertion;
83114

84115
/**
@@ -99,56 +130,82 @@ export interface Assertions {
99130
*/
100131
throwsAsync: ThrowsAsyncAssertion;
101132

102-
/** Assert that `actual` is strictly true. */
133+
/**
134+
* Assert that `actual` is strictly true, returning Boolean indicating
135+
* whether the assertion passes.
136+
*/
103137
true: TrueAssertion;
104138

105-
/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
139+
/**
140+
* Assert that `actual` is
141+
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
142+
* returning Boolean indicating whether the assertion passes.
143+
*/
106144
truthy: TruthyAssertion;
107145
}
108146

109147
export interface AssertAssertion {
110-
/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */
111-
(actual: any, message?: string): void;
148+
/**
149+
* Assert that `actual` is
150+
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
151+
* returning Boolean indicating whether the assertion passes. Comes with
152+
* power-assert.
153+
*/
154+
(actual: any, message?: string): boolean;
112155

113156
/** Skip this assertion. */
114157
skip(actual: any, message?: string): void;
115158
}
116159

117160
export interface DeepEqualAssertion {
118-
/** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
119-
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
161+
/**
162+
* Assert that `actual` is [deeply
163+
* equal](https://github.com/concordancejs/concordance#comparison-details) to
164+
* `expected`, returning Boolean indicating whether the assertion passes.
165+
*/
166+
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;
120167

121168
/** Skip this assertion. */
122169
skip(actual: any, expected: any, message?: string): void;
123170
}
124171

125172
export interface LikeAssertion {
126-
/** Assert that `value` is like `selector`. */
127-
(value: any, selector: Record<string, any>, message?: string): void;
173+
/**
174+
* Assert that `value` is like `selector`, returning Boolean indicating
175+
* whether the assertion passes.
176+
*/
177+
(value: any, selector: Record<string, any>, message?: string): boolean;
128178

129179
/** Skip this assertion. */
130180
skip(value: any, selector: any, message?: string): void;
131181
}
132182

133183
export interface FailAssertion {
134-
/** Fail the test. */
135-
(message?: string): void;
184+
/** Fail the test, always returning `false`. */
185+
(message?: string): false;
136186

137187
/** Skip this assertion. */
138188
skip(message?: string): void;
139189
}
140190

141191
export interface FalseAssertion {
142-
/** Assert that `actual` is strictly false. */
143-
(actual: any, message?: string): void;
192+
/**
193+
* Assert that `actual` is strictly false, returning Boolean indicating
194+
* whether the assertion passes.
195+
*/
196+
(actual: any, message?: string): boolean;
144197

145198
/** Skip this assertion. */
146199
skip(actual: any, message?: string): void;
147200
}
148201

149202
export interface FalsyAssertion {
150-
/** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
151-
(actual: any, message?: string): void;
203+
/**
204+
* Assert that `actual` is
205+
* [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning
206+
* Boolean whether the assertion passes.
207+
*/
208+
(actual: any, message?: string): boolean;
152209

153210
/** Skip this assertion. */
154211
skip(actual: any, message?: string): void;
@@ -157,9 +214,10 @@ export interface FalsyAssertion {
157214
export interface IsAssertion {
158215
/**
159216
* Assert that `actual` is [the same
160-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
217+
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
218+
* as `expected`, returning Boolean indicating whether the assertion passes.
161219
*/
162-
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
220+
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;
163221

164222
/** Skip this assertion. */
165223
skip(actual: any, expected: any, message?: string): void;
@@ -168,25 +226,33 @@ export interface IsAssertion {
168226
export interface NotAssertion {
169227
/**
170228
* Assert that `actual` is not [the same
171-
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
229+
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
230+
* as `expected`, returning Boolean indicating whether the assertion passes.
172231
*/
173-
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
232+
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;
174233

175234
/** Skip this assertion. */
176235
skip(actual: any, expected: any, message?: string): void;
177236
}
178237

179238
export interface NotDeepEqualAssertion {
180-
/** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
181-
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
239+
/**
240+
* Assert that `actual` is not [deeply
241+
* equal](https://github.com/concordancejs/concordance#comparison-details) to
242+
* `expected`, returning Boolean indicating whether the assertion passes.
243+
*/
244+
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;
182245

183246
/** Skip this assertion. */
184247
skip(actual: any, expected: any, message?: string): void;
185248
}
186249

187250
export interface NotRegexAssertion {
188-
/** Assert that `string` does not match the regular expression. */
189-
(string: string, regex: RegExp, message?: string): void;
251+
/**
252+
* Assert that `string` does not match the regular expression, returning
253+
* Boolean indicating whether the assertion passes.
254+
*/
255+
(string: string, regex: RegExp, message?: string): boolean;
190256

191257
/** Skip this assertion. */
192258
skip(string: string, regex: RegExp, message?: string): void;
@@ -212,16 +278,19 @@ export interface NotThrowsAsyncAssertion {
212278
}
213279

214280
export interface PassAssertion {
215-
/** Count a passing assertion. */
216-
(message?: string): void;
281+
/** Count a passing assertion, always returning `true`. */
282+
(message?: string): true;
217283

218284
/** Skip this assertion. */
219285
skip(message?: string): void;
220286
}
221287

222288
export interface RegexAssertion {
223-
/** Assert that `string` matches the regular expression. */
224-
(string: string, regex: RegExp, message?: string): void;
289+
/**
290+
* Assert that `string` matches the regular expression, returning Boolean
291+
* indicating whether the assertion passes.
292+
*/
293+
(string: string, regex: RegExp, message?: string): boolean;
225294

226295
/** Skip this assertion. */
227296
skip(string: string, regex: RegExp, message?: string): void;
@@ -235,8 +304,18 @@ export interface SnapshotAssertion {
235304
*/
236305
(expected: any, message?: string): void;
237306

307+
/**
308+
* Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
309+
* previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details) (selected
310+
* through `options.id` if provided), or if necessary record a new snapshot.
311+
*/
312+
(expected: any, options: SnapshotOptions, message?: string): void;
313+
238314
/** Skip this assertion. */
239315
skip(expected: any, message?: string): void;
316+
317+
/** Skip this assertion. */
318+
skip(expected: any, options: SnapshotOptions, message?: string): void;
240319
}
241320

242321
export interface ThrowsAssertion {
@@ -280,16 +359,23 @@ export interface ThrowsAsyncAssertion {
280359
}
281360

282361
export interface TrueAssertion {
283-
/** Assert that `actual` is strictly true. */
284-
(actual: any, message?: string): void;
362+
/**
363+
* Assert that `actual` is strictly true, returning Boolean indicating
364+
* whether the assertion passes.
365+
*/
366+
(actual: any, message?: string): boolean;
285367

286368
/** Skip this assertion. */
287369
skip(actual: any, message?: string): void;
288370
}
289371

290372
export interface TruthyAssertion {
291-
/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
292-
(actual: any, message?: string): void;
373+
/**
374+
* Assert that `actual` is
375+
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
376+
* returning Boolean indicating whether the assertion passes.
377+
*/
378+
(actual: any, message?: string): boolean;
293379

294380
/** Skip this assertion. */
295381
skip(actual: any, message?: string): void;

0 commit comments

Comments
 (0)