/
macros.ts
79 lines (65 loc) 路 1.79 KB
/
macros.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import test, {ExecutionContext, Macro} from '../..';
// Explicitly type as a macro.
{
const hasLength: Macro<[string, number]> = (t, input, expected) => {
t.is(input.length, expected);
};
test('bar has length 3', hasLength, 'bar', 3);
test('bar has length 3', [hasLength], 'bar', 3);
}
// Infer macro
{
const hasLength = (t: ExecutionContext, input: string, expected: number) => {
t.is(input.length, expected);
};
test('bar has length 3', hasLength, 'bar', 3);
test('bar has length 3', [hasLength], 'bar', 3);
}
// Multiple macros
{
const hasLength = (t: ExecutionContext, input: string, expected: number) => {
t.is(input.length, expected);
};
const hasCodePoints = (t: ExecutionContext, input: string, expected: number) => {
t.is(Array.from(input).length, expected);
};
test('bar has length 3', [hasLength, hasCodePoints], 'bar', 3);
}
// No title
{
const hasLength: Macro<[string, number]> = (t, input, expected) => {
t.is(input.length, expected);
};
const hasCodePoints: Macro<[string, number]> = (t, input, expected) => {
t.is(Array.from(input).length, expected);
};
test(hasLength, 'bar', 3);
test([hasLength, hasCodePoints], 'bar', 3);
}
// No arguments
{
const pass: Macro<[]> = t => t.pass()
pass.title = () => 'pass'
test(pass)
}
// Inline
{
test('has length 3', (t: ExecutionContext, input: string, expected: number) => {
t.is(input.length, expected)
}, 'bar', 3)
test((t: ExecutionContext, input: string, expected: number) => {
t.is(input.length, expected)
}, 'bar', 3)
}
// Completely infer parameters
{
test('has length 3', (t, input, expected) => {
t.is(input.length, expected);
}, 'foo', 3);
test((t, input, expected) => {
t.is(input.length, expected)
}, 'foo', 3);
test.skip((t, input, expected) => {
t.is(input.length, expected)
}, 'foo', 3);
}