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: readme.md
+26-34Lines changed: 26 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,6 @@ import test from 'ava';
40
40
41
41
test(t=> {
42
42
t.same([1, 2], [1, 2]);
43
-
t.end();
44
43
});
45
44
```
46
45
@@ -58,7 +57,7 @@ Install AVA globally `$ npm install --global ava` and run `$ ava --init` (with a
58
57
"test": "ava"
59
58
},
60
59
"devDependencies": {
61
-
"ava": "^0.3.0"
60
+
"ava": "^0.6.0"
62
61
}
63
62
}
64
63
```
@@ -73,12 +72,12 @@ test('foo', t => {
73
72
t.pass();
74
73
});
75
74
76
-
constbar=Promise.resolve('bar').then(delay(200));
77
-
78
75
test('bar', asynct=> {
79
76
t.plan(2);
80
-
81
-
t.is(await bar, 'bar');
77
+
78
+
constbar=Promise.resolve('bar').then(delay(200));
79
+
80
+
t.is(await bar, 'bar');
82
81
});
83
82
```
84
83
@@ -120,11 +119,11 @@ Files starting with `_` are ignored. This can be useful for having helpers in th
120
119
121
120
## Documentation
122
121
123
-
Tests are run asynchronously and require you to return a supported async object (a promise, or [observable](https://github.com/zenparsing/zen-observable)). We *highly* recommend the use of [async functions](#async-function-support); They make async code concise and readable, and they implicitly return a promise, so you don't need to.
122
+
Tests are run asynchronously and require you to return a supported async object (a promise, or [observable](https://github.com/zenparsing/zen-observable)). We *highly* recommend the use of [async functions](#async-function-support); They make async code concise and readable, and they implicitly return a promise, so you don't have to.
124
123
125
-
If you do not return one of the supported async objects mentioned above, the test is considered to be synchronous and ended immediately.
124
+
If you don't return one of the supported async objects mentioned above, the test is considered to be synchronous and ended immediately.
126
125
127
-
If you are unable to use promises or other supported async objects, you may enable legacy async support by defining your test with `test.async([title', fn)`. Tests declared this way **must** be manually ended with `t.end()`.
126
+
If you're unable to use promises or other supported async objects, you may enable legacy async support by defining your test with `test.async([title', fn)`. Tests declared this way **must** be manually ended with `t.end()`. This mode is mainly intended for testing callback-style APIs.
128
127
129
128
You must define all tests synchronously. They can't be defined inside `setTimeout`, `setImmediate`, etc.
130
129
@@ -160,9 +159,7 @@ test(function name(t) {
160
159
161
160
### Assertion plan
162
161
163
-
An assertion plan can be used to ensure a specific number of assertions are made.
164
-
In the most common scenario, it validates that the test did not exit before executing the expected number of assertions.
165
-
It also fails the test if too many assertions are executed (Useful if you have assertions inside callbacks or loops).
162
+
An assertion plan can be used to ensure a specific number of assertions are made. In the most common scenario, it validates that the test didn't exit before executing the expected number of assertions. It also fails the test if too many assertions are executed, which can be useful if you have assertions inside callbacks or loops.
166
163
167
164
This will result in a passed test:
168
165
@@ -185,32 +182,31 @@ test.async(t => {
185
182
186
183
#### WARNING: Recent breaking change.
187
184
188
-
AVA no longer supports automatically ending tests via `t.plan(...)`.
189
-
This helps prevent false positives if you add assertions, but forget to increase your plan count.
185
+
AVA no longer supports automatically ending tests via `t.plan(...)`. This helps prevent false positives if you add assertions, but forget to increase your plan count.
190
186
191
187
```js
192
188
// This no longer works
193
189
194
190
test('auto ending is dangerous', t=> {
195
191
t.plan(2);
196
-
192
+
197
193
t.pass();
198
194
t.pass();
199
-
195
+
200
196
// auto-ending after reaching the planned two assertions will miss this final one
201
197
setTimeout(() =>t.fail(), 10000);
202
198
});
203
199
```
204
200
205
-
For this to work, you now must use the legacy `async` test mode, and explicitly call `t.end()`.
206
-
201
+
For this to work, you must now use the legacy `async` test mode, and explicitly call `t.end()`.
202
+
207
203
```js
208
204
test('explicitly end your tests', t=> {
209
205
t.plan(2);
210
-
206
+
211
207
t.pass();
212
208
t.pass();
213
-
209
+
214
210
setTimeout(() => {
215
211
// This failure is now reliably caught.
216
212
t.fail();
@@ -249,7 +245,7 @@ Skip-tests are shown in the output as skipped but never run.
249
245
250
246
```js
251
247
test.skip('will not be run', t=> {
252
-
t.fail();
248
+
t.fail();
253
249
});
254
250
```
255
251
@@ -289,15 +285,15 @@ Both modern and legacy async support are available for hooks
289
285
290
286
```js
291
287
test.before(asynct=> {
292
-
awaitpromiseFn();
288
+
awaitpromiseFn();
293
289
});
294
290
295
291
test.async.beforeEach(t=> {
296
-
setTimeout(t.end);
292
+
setTimeout(t.end);
297
293
});
298
294
299
295
test.afterEach.async(t=> {
300
-
setTimeout(t.end);
296
+
setTimeout(t.end);
301
297
});
302
298
```
303
299
@@ -367,7 +363,7 @@ You can also use your own local Babel version:
367
363
```json
368
364
{
369
365
"devDependencies": {
370
-
"ava": "^0.3.0",
366
+
"ava": "^0.6.0",
371
367
"babel-core": "^5.8.0"
372
368
}
373
369
}
@@ -414,8 +410,6 @@ test(function * (t) {
414
410
});
415
411
```
416
412
417
-
*You don't have to manually call `t.end()`.*
418
-
419
413
### Async function support
420
414
421
415
AVA comes with builtin support for [async functions](https://tc39.github.io/ecmascript-asyncawait/)*(async/await)*.
@@ -437,6 +431,7 @@ test(async t => {
437
431
438
432
AVA comes with builtin support for [observables](https://github.com/zenparsing/es-observable).
439
433
If you return an observable from a test, AVA will automatically consume it to completion before ending the test.
434
+
440
435
*You don't have to use legacy `test.async` mode or `t.end()`.*
441
436
442
437
```js
@@ -453,9 +448,7 @@ test(t => {
453
448
454
449
### Callback support
455
450
456
-
AVA supports using `t.end` as the final callback when using node-style
457
-
error-first callback APIs. AVA will consider any truthy value passed as
458
-
the first argument to `t.end` to be an error. Note that `t.end` requires legacy `test.async` mode.
451
+
AVA supports using `t.end` as the final callback when using node-style error-first callback APIs. AVA will consider any truthy value passed as the first argument to `t.end` to be an error. Note that `t.end` requires legacy `test.async` mode.
459
452
460
453
```js
461
454
test.async(t=> {
@@ -469,6 +462,7 @@ test.async(t => {
469
462
470
463
### test([title], body)
471
464
### test.serial([title], body)
465
+
### test.async([title], body)
472
466
### test.only([title], body)
473
467
### test.skip([title], body)
474
468
### test.before([title], body)
@@ -494,13 +488,11 @@ Passed into the test function and contains the different AVA methods and [assert
494
488
495
489
###### .plan(count)
496
490
497
-
Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match planned assertions. When planned assertions are used you don't need to explicitly end the test.
498
-
499
-
Be aware that this doesn't work with custom assert modules. You must then call `.end()` explicitly.
491
+
Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match planned assertions.
0 commit comments