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/01-writing-tests.md
+4-10
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,9 @@ test('handles observables', t => {
93
93
94
94
## Callback support
95
95
96
-
AVA supports using `t.end` as the final callback when using Node.js-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.
96
+
*👉 AVA 4 removes support for `test.cb()` and `t.end()`.*
97
+
98
+
AVA 3 supports using `t.end` as the final callback when using Node.js-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.
97
99
98
100
```js
99
101
test.cb('data.txt can be read', t=> {
@@ -223,7 +225,7 @@ test('title', t => {
223
225
});
224
226
```
225
227
226
-
Hooks can be synchronous or asynchronous, just like tests. To make a hook asynchronous return a promise or observable, use an async function, or enable callback mode via `test.before.cb()`, `test.beforeEach.cb()` etc.
228
+
Hooks can be synchronous or asynchronous, just like tests. To make a hook asynchronous return a promise or observable, or use an async function.
227
229
228
230
```js
229
231
test.before(asynct=> {
@@ -233,14 +235,6 @@ test.before(async t => {
233
235
test.after(t=> {
234
236
returnnewPromise(/* ... */);
235
237
});
236
-
237
-
test.beforeEach.cb(t=> {
238
-
setTimeout(t.end);
239
-
});
240
-
241
-
test.afterEach.cb(t=> {
242
-
setTimeout(t.end);
243
-
});
244
238
```
245
239
246
240
Keep in mind that the `.beforeEach()` and `.afterEach()` hooks run just before and after a test is run, and that by default tests run concurrently. This means each multiple `.beforeEach()` hooks may run concurrently. Using `test.serial.beforeEach()` does not change this. If you need to set up global state for each test (like spying on `console.log`[for example](https://github.com/avajs/ava/issues/560)), you'll need to make sure the tests themselves are [run serially](#running-tests-serially).
Copy file name to clipboardExpand all lines: docs/08-common-pitfalls.md
+3-12
Original file line number
Diff line number
Diff line change
@@ -39,22 +39,13 @@ test('fetches foo', async t => {
39
39
});
40
40
```
41
41
42
-
If you're using callbacks, use [`test.cb`](./01-writing-tests.md#callback-support):
42
+
If you're using callbacks, promisify the callback function using something like [`util.promisify()`](https://nodejs.org/dist/latest/docs/api/util.html#util_util_promisify_original):
43
43
44
44
```js
45
-
test.cb('fetches foo', t=> {
46
-
fetch((err, data) => {
47
-
t.is(data, 'foo');
48
-
t.end();
49
-
});
50
-
});
51
-
```
52
-
53
-
Alternatively, promisify the callback function using something like [`pify`](https://github.com/sindresorhus/pify):
Copy file name to clipboardExpand all lines: docs/recipes/when-to-use-plan.md
-19
Original file line number
Diff line number
Diff line change
@@ -93,25 +93,6 @@ As stated in the previous example, using the `t.throws()` assertion with `async`
93
93
94
94
`t.plan()` provides value in the following cases.
95
95
96
-
### Ensuring multiple callbacks are actually called
97
-
98
-
```js
99
-
test.cb('invokes callbacks', t=> {
100
-
t.plan(2);
101
-
102
-
constcallbackA= () => {
103
-
t.pass();
104
-
t.end();
105
-
};
106
-
107
-
constcallbackB= () =>t.pass();
108
-
109
-
bThenA(callbackA, callbackB);
110
-
});
111
-
```
112
-
113
-
The above ensures `callbackB` is called first (and only once), followed by `callbackA`. Any other combination would not satisfy the plan.
114
-
115
96
### Tests with branching statements
116
97
117
98
In most cases, it's a bad idea to use any complex branching inside your tests. A notable exception is for tests that are auto-generated (perhaps from a JSON document). Below `t.plan()` is used to ensure the correctness of the JSON input:
0 commit comments