Skip to content

Commit 76152ed

Browse files
committed
readme cleanup
1 parent 2a7a639 commit 76152ed

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

readme.md

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import test from 'ava';
4040

4141
test(t => {
4242
t.same([1, 2], [1, 2]);
43-
t.end();
4443
});
4544
```
4645

@@ -58,7 +57,7 @@ Install AVA globally `$ npm install --global ava` and run `$ ava --init` (with a
5857
"test": "ava"
5958
},
6059
"devDependencies": {
61-
"ava": "^0.3.0"
60+
"ava": "^0.6.0"
6261
}
6362
}
6463
```
@@ -73,12 +72,12 @@ test('foo', t => {
7372
t.pass();
7473
});
7574

76-
const bar = Promise.resolve('bar').then(delay(200));
77-
7875
test('bar', async t => {
7976
t.plan(2);
80-
81-
t.is(await bar, 'bar');
77+
78+
const bar = Promise.resolve('bar').then(delay(200));
79+
80+
t.is(await bar, 'bar');
8281
});
8382
```
8483

@@ -120,11 +119,11 @@ Files starting with `_` are ignored. This can be useful for having helpers in th
120119

121120
## Documentation
122121

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.
124123

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.
126125

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.
128127

129128
You must define all tests synchronously. They can't be defined inside `setTimeout`, `setImmediate`, etc.
130129

@@ -160,9 +159,7 @@ test(function name(t) {
160159

161160
### Assertion plan
162161

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.
166163

167164
This will result in a passed test:
168165

@@ -185,32 +182,31 @@ test.async(t => {
185182

186183
#### WARNING: Recent breaking change.
187184

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.
190186

191187
```js
192188
// This no longer works
193189

194190
test('auto ending is dangerous', t => {
195191
t.plan(2);
196-
192+
197193
t.pass();
198194
t.pass();
199-
195+
200196
// auto-ending after reaching the planned two assertions will miss this final one
201197
setTimeout(() => t.fail(), 10000);
202198
});
203199
```
204200

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+
207203
```js
208204
test('explicitly end your tests', t => {
209205
t.plan(2);
210-
206+
211207
t.pass();
212208
t.pass();
213-
209+
214210
setTimeout(() => {
215211
// This failure is now reliably caught.
216212
t.fail();
@@ -249,7 +245,7 @@ Skip-tests are shown in the output as skipped but never run.
249245

250246
```js
251247
test.skip('will not be run', t => {
252-
t.fail();
248+
t.fail();
253249
});
254250
```
255251

@@ -289,15 +285,15 @@ Both modern and legacy async support are available for hooks
289285

290286
```js
291287
test.before(async t => {
292-
await promiseFn();
288+
await promiseFn();
293289
});
294290

295291
test.async.beforeEach(t => {
296-
setTimeout(t.end);
292+
setTimeout(t.end);
297293
});
298294

299295
test.afterEach.async(t => {
300-
setTimeout(t.end);
296+
setTimeout(t.end);
301297
});
302298
```
303299

@@ -367,7 +363,7 @@ You can also use your own local Babel version:
367363
```json
368364
{
369365
"devDependencies": {
370-
"ava": "^0.3.0",
366+
"ava": "^0.6.0",
371367
"babel-core": "^5.8.0"
372368
}
373369
}
@@ -414,8 +410,6 @@ test(function * (t) {
414410
});
415411
```
416412

417-
*You don't have to manually call `t.end()`.*
418-
419413
### Async function support
420414

421415
AVA comes with builtin support for [async functions](https://tc39.github.io/ecmascript-asyncawait/) *(async/await)*.
@@ -437,6 +431,7 @@ test(async t => {
437431

438432
AVA comes with builtin support for [observables](https://github.com/zenparsing/es-observable).
439433
If you return an observable from a test, AVA will automatically consume it to completion before ending the test.
434+
440435
*You don't have to use legacy `test.async` mode or `t.end()`.*
441436

442437
```js
@@ -453,9 +448,7 @@ test(t => {
453448

454449
### Callback support
455450

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.
459452

460453
```js
461454
test.async(t => {
@@ -469,6 +462,7 @@ test.async(t => {
469462

470463
### test([title], body)
471464
### test.serial([title], body)
465+
### test.async([title], body)
472466
### test.only([title], body)
473467
### test.skip([title], body)
474468
### test.before([title], body)
@@ -494,13 +488,11 @@ Passed into the test function and contains the different AVA methods and [assert
494488

495489
###### .plan(count)
496490

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.
500492

501493
###### .end()
502494

503-
End the test. Use this when `plan()` is not used.
495+
End the test. Only works with `test.async()`.
504496

505497

506498
## Assertions

0 commit comments

Comments
 (0)