-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathfake-async-flush_spec.ts
More file actions
108 lines (95 loc) · 3.07 KB
/
fake-async-flush_spec.ts
File metadata and controls
108 lines (95 loc) · 3.07 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { expectTransformation } from '../test-helpers';
describe('transformFakeAsyncFlush', () => {
const testCases = [
{
description: 'should replace `flush` with `await vi.runAllTimersAsync()`',
input: `
import { flush } from '@angular/core/testing';
flush();
`,
expected: `await vi.runAllTimersAsync();`,
},
{
description: 'should add TODO comment when flush is called with maxTurns',
input: `
import { flush } from '@angular/core/testing';
flush(42);
`,
expected: `
// TODO: vitest-migration: flush(maxTurns) was called but maxTurns parameter is not migrated. Please migrate manually.
await vi.runAllTimersAsync();
`,
},
{
description: 'should add TODO comment when flush return value is used',
input: `
import { flush } from '@angular/core/testing';
const turns = flush();
`,
expected: `
// TODO: vitest-migration: flush() return value is not migrated. Please migrate manually.
const turns = await vi.runAllTimersAsync() ?? 0;
`,
},
{
description: 'should add TODO comment when flush return value is used in a return statement',
input: `
import { flush } from '@angular/core/testing';
async function myFlushWrapper() {
return flush();
}
`,
expected: `
async function myFlushWrapper() {
// TODO: vitest-migration: flush() return value is not migrated. Please migrate manually.
return await vi.runAllTimersAsync() ?? 0;
}
`,
},
{
description: 'should not replace `flush` if not imported from `@angular/core/testing`',
input: `
import { flush } from './my-flush';
flush();
`,
expected: `
import { flush } from './my-flush';
flush();
`,
},
{
description: 'should keep other imported symbols from `@angular/core/testing`',
input: `
import { TestBed, flush } from '@angular/core/testing';
flush();
`,
expected: `
import { TestBed } from '@angular/core/testing';
await vi.runAllTimersAsync();
`,
},
{
description: 'should keep imported types from `@angular/core/testing`',
input: `
import { flush, type ComponentFixture } from '@angular/core/testing';
flush();
`,
expected: `
import { type ComponentFixture } from '@angular/core/testing';
await vi.runAllTimersAsync();
`,
},
];
testCases.forEach(({ description, input, expected }) => {
it(description, async () => {
await expectTransformation(input, expected);
});
});
});