Skip to content

Commit f98a881

Browse files
mightyiamnovemberborn
authored andcommitted
Document how to title macros when using TypeScript
1 parent b3c4090 commit f98a881

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/recipes/typescript.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ test(async (t) => {
5050
});
5151
```
5252

53+
## Working with [macros](https://github.com/avajs/ava#test-macros)
54+
55+
In order to be able to assign the `title` property to a macro:
56+
57+
```ts
58+
import test, { AssertContext, Macro } from 'ava';
59+
60+
const macro: Macro<AssertContext> = (t, input, expected) => {
61+
t.is(eval(input), expected);
62+
}
63+
64+
macro.title = (providedTitle, input, expected) => `${providedTitle} ${input} = ${expected}`.trim();
65+
66+
test(macro, '2 + 2', 4);
67+
test(macro, '2 * 3', 6);
68+
test('providedTitle', macro, '3 * 3', 9);
69+
```
5370

5471
## Working with [`context`](https://github.com/avajs/ava#test-context)
5572

0 commit comments

Comments
 (0)