You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/03-assertions.md
+26-14
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,8 @@ test('unicorns are truthy', t => {
21
21
22
22
If multiple assertion failures are encountered within a single test, AVA will only display the *first* one.
23
23
24
+
Assertions return a boolean indicating whether they passed. You can use this to return early from a test. Note that this does not apply to the "throws" assertions.
25
+
24
26
## Assertion planning
25
27
26
28
Assertion plans ensure tests only pass when a specific number of assertions have been executed. They'll help you catch cases where tests exit too early. They'll also cause tests to fail if too many assertions are executed, which can be useful if you have assertions inside callbacks or loops.
@@ -165,47 +167,47 @@ test('custom assertion', t => {
165
167
166
168
### `.pass(message?)`
167
169
168
-
Passing assertion.
170
+
Passing assertion. Returns a boolean indicating whether the assertion passed.
169
171
170
172
### `.fail(message?)`
171
173
172
-
Failing assertion.
174
+
Failing assertion. Returns a boolean indicating whether the assertion passed.
173
175
174
176
### `.assert(value, message?)`
175
177
176
-
Asserts that `value` is truthy. This is [`power-assert`](#enhanced-assertion-messages) enabled.
178
+
Asserts that `value` is truthy. This is [`power-assert`](#enhanced-assertion-messages) enabled. Returns a boolean indicating whether the assertion passed.
177
179
178
180
### `.truthy(value, message?)`
179
181
180
-
Assert that `value` is truthy.
182
+
Assert that `value` is truthy. Returns a boolean indicating whether the assertion passed.
181
183
182
184
### `.falsy(value, message?)`
183
185
184
-
Assert that `value` is falsy.
186
+
Assert that `value` is falsy. Returns a boolean indicating whether the assertion passed.
185
187
186
188
### `.true(value, message?)`
187
189
188
-
Assert that `value` is `true`.
190
+
Assert that `value` is `true`. Returns a boolean indicating whether the assertion passed.
189
191
190
192
### `.false(value, message?)`
191
193
192
-
Assert that `value` is `false`.
194
+
Assert that `value` is `false`. Returns a boolean indicating whether the assertion passed.
193
195
194
196
### `.is(value, expected, message?)`
195
197
196
-
Assert that `value` is the same as `expected`. This is based on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
198
+
Assert that `value` is the same as `expected`. This is based on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). Returns a boolean indicating whether the assertion passed.
197
199
198
200
### `.not(value, expected, message?)`
199
201
200
-
Assert that `value` is not the same as `expected`. This is based on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
202
+
Assert that `value` is not the same as `expected`. This is based on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). Returns a boolean indicating whether the assertion passed.
201
203
202
204
### `.deepEqual(value, expected, message?)`
203
205
204
206
Assert that `value` is deeply equal to `expected`. See [Concordance](https://github.com/concordancejs/concordance) for details. In AVA 3 this works with [React elements and `react-test-renderer`](https://github.com/concordancejs/react).
205
207
206
208
### `.notDeepEqual(value, expected, message?)`
207
209
208
-
Assert that `value` is not deeply equal to `expected`. The inverse of `.deepEqual()`.
210
+
Assert that `value` is not deeply equal to `expected`. The inverse of `.deepEqual()`. Returns a boolean indicating whether the assertion passed.
209
211
210
212
### `.like(value, selector, message?)`
211
213
@@ -232,6 +234,8 @@ t.like({
232
234
})
233
235
```
234
236
237
+
Finally, this returns a boolean indicating whether the assertion passed.
238
+
235
239
### `.throws(fn, expectation?, message?)`
236
240
237
241
Assert that an error is thrown. `fn` must be a function which should throw. The thrown value *must* be an error. It is returned so you can run more assertions against it.
Assert that an error is thrown. `thrower` can be an async function which should throw, or a promise that should reject. This assertion must be awaited.
@@ -297,9 +303,11 @@ test('rejects', async t => {
297
303
});
298
304
```
299
305
306
+
Does not return anything.
307
+
300
308
### `.notThrows(fn, message?)`
301
309
302
-
Assert that no error is thrown. `fn` must be a function which shouldn't throw.
310
+
Assert that no error is thrown. `fn` must be a function which shouldn't throw. Does not return anything.
303
311
304
312
### `.notThrowsAsync(nonThrower, message?)`
305
313
@@ -313,21 +321,23 @@ test('resolves', async t => {
313
321
});
314
322
```
315
323
324
+
Does not return anything.
325
+
316
326
### `.regex(contents, regex, message?)`
317
327
318
-
Assert that `contents` matches `regex`.
328
+
Assert that `contents` matches `regex`. Returns a boolean indicating whether the assertion passed.
319
329
320
330
### `.notRegex(contents, regex, message?)`
321
331
322
-
Assert that `contents` does not match `regex`.
332
+
Assert that `contents` does not match `regex`. Returns a boolean indicating whether the assertion passed.
323
333
324
334
### `.snapshot(expected, message?)`
325
335
326
336
Compares the `expected` value with a previously recorded snapshot. Snapshots are stored for each test, so ensure you give your tests unique titles.
327
337
328
338
AVA 3 supports an `options` object that lets you select a specific snapshot, for instance `{id: 'my snapshot'}`. This is buggy and will be removed in AVA 4.
329
339
330
-
Snapshot assertions cannot be skipped when snapshots are being updated.
340
+
Snapshot assertions cannot be skipped when snapshots are being updated. Returns a boolean indicating whether the assertion passed.
0 commit comments