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: lib/test.js
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -142,8 +142,8 @@ Test.prototype.run = function () {
142
142
}
143
143
144
144
if(isPromise(ret)){
145
-
if(this.metadata.async){
146
-
self._setAssertError(newError('Do not return '+asyncType+' from tests declared via `test.async(...)`, if you want to return a promise simply declare the test via `test(...)`'));
145
+
if(this.metadata.callback){
146
+
self._setAssertError(newError('Do not return '+asyncType+' from tests declared via `test.cb(...)`, if you want to return a promise simply declare the test via `test(...)`'));
147
147
this.exit();
148
148
returnthis.promise.promise;
149
149
}
@@ -161,7 +161,7 @@ Test.prototype.run = function () {
161
161
162
162
self.exit();
163
163
});
164
-
}elseif(!this.metadata.async){
164
+
}elseif(!this.metadata.callback){
165
165
this.exit();
166
166
}
167
167
@@ -170,10 +170,10 @@ Test.prototype.run = function () {
170
170
171
171
Object.defineProperty(Test.prototype,'end',{
172
172
get: function(){
173
-
if(this.metadata.async){
173
+
if(this.metadata.callback){
174
174
returnthis._end;
175
175
}
176
-
thrownewError('t.end is not supported in this context. To use t.end as a callback, you must explicitly declare the test asynchronous via `test.async(testName, fn)` ');
176
+
thrownewError('t.end is not supported in this context. To use t.end as a callback, you must use "callback mode" via `test.cb(testName, fn)` ');
Copy file name to clipboardExpand all lines: readme.md
+16-12Lines changed: 16 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,7 +124,7 @@ Tests are run asynchronously and require you to return a supported async object
124
124
125
125
If you don't return one of the supported async objects mentioned above, the test is considered to be synchronous and ended immediately.
126
126
127
-
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.
127
+
If you're unable to use promises or other supported async objects, you may enable "callback mode" by defining your test with `test.cb([title', fn)`. Tests declared this way **must** be manually ended with `t.end()`. This mode is mainly intended for testing callback-style APIs.
128
128
129
129
You must define all tests synchronously. They can't be defined inside `setTimeout`, `setImmediate`, etc.
130
130
@@ -173,7 +173,7 @@ test(t => {
173
173
});
174
174
});
175
175
176
-
test.async(t=> {
176
+
test.cb(t=> {
177
177
setTimeout(() => {
178
178
t.pass();
179
179
t.end();
@@ -199,10 +199,10 @@ test('auto ending is dangerous', t => {
199
199
});
200
200
```
201
201
202
-
For this to work, you must now use the legacy `async` test mode, and explicitly call `t.end()`.
202
+
For this to work, you must now use "callback mode", and explicitly call `t.end()`.
203
203
204
204
```js
205
-
test('explicitly end your tests', t=> {
205
+
test.cb('explicitly end your tests', t=> {
206
206
t.plan(2);
207
207
208
208
t.pass();
@@ -282,20 +282,24 @@ test(t => {
282
282
});
283
283
```
284
284
285
-
Both modern and legacy async support are available for hooks
285
+
You may use async functions, return async objects, or enable "callback mode" in any of the hooks.
286
286
287
287
```js
288
288
test.before(asynct=> {
289
289
awaitpromiseFn();
290
290
});
291
291
292
-
test.async.beforeEach(t=> {
292
+
test.cb.beforeEach(t=> {
293
293
setTimeout(t.end);
294
294
});
295
295
296
-
test.afterEach.async(t=> {
296
+
test.afterEach.cb(t=> {
297
297
setTimeout(t.end);
298
298
});
299
+
300
+
test.after(t=> {
301
+
returnnewPromise(/* ... */);
302
+
});
299
303
```
300
304
301
305
The `beforeEach` & `afterEach` hooks can share context with the test:
@@ -433,7 +437,7 @@ test(async t => {
433
437
AVA comes with builtin support for [observables](https://github.com/zenparsing/es-observable).
434
438
If you return an observable from a test, AVA will automatically consume it to completion before ending the test.
435
439
436
-
*You don't have to use legacy `test.async`mode or `t.end()`.*
440
+
*You do not need to use "callback mode" or call`t.end()`.*
437
441
438
442
```js
439
443
test(t=> {
@@ -449,10 +453,10 @@ test(t => {
449
453
450
454
### Callback support
451
455
452
-
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.
456
+
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 "callback mode", which can be enabled by using the `test.cb` chain.
453
457
454
458
```js
455
-
test.async(t=> {
459
+
test.cb(t=> {
456
460
// t.end automatically checks for error as first argument
457
461
fs.readFile('data.txt', t.end);
458
462
});
@@ -463,7 +467,7 @@ test.async(t => {
463
467
464
468
### test([title], body)
465
469
### test.serial([title], body)
466
-
### test.async([title], body)
470
+
### test.cb([title], body)
467
471
### test.only([title], body)
468
472
### test.skip([title], body)
469
473
### test.before([title], body)
@@ -493,7 +497,7 @@ Plan how many assertion there are in the test. The test will fail if the actual
0 commit comments