Skip to content

Commit 4b88f13

Browse files
committed
fixup! feat(@schematics/angular): migrate fake async to Vitest fake timers
1 parent 24627cd commit 4b88f13

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/schematics/angular/refactor/jasmine-vitest/transformers/fake-async-tick.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export function transformFakeAsyncTick(node: ts.Node, ctx: RefactorContext): ts.
3333
addImportSpecifierRemoval(ctx, 'tick', ANGULAR_CORE_TESTING);
3434

3535
const durationNumericLiteral =
36-
node.arguments.length > 0 && ts.isNumericLiteral(node.arguments[0])
37-
? node.arguments[0]
38-
: ts.factory.createNumericLiteral(0);
36+
node.arguments.length > 0 ? node.arguments[0] : ts.factory.createNumericLiteral(0);
3937

4038
return ts.factory.createAwaitExpression(
4139
createViCallExpression(ctx, 'advanceTimersByTimeAsync', [durationNumericLiteral]),

packages/schematics/angular/refactor/jasmine-vitest/transformers/fake-async-tick_spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ describe('transformFakeAsyncTick', () => {
1919
`,
2020
expected: `await vi.advanceTimersByTimeAsync(100);`,
2121
},
22+
{
23+
description:
24+
'should replace `tick` with `vi.advanceTimersByTimeAsync` even if it using a non-literal argument',
25+
input: `
26+
import { tick } from '@angular/core/testing';
27+
28+
const duration = 100;
29+
tick(duration);
30+
`,
31+
expected: `await vi.advanceTimersByTimeAsync(100);`,
32+
},
2233
{
2334
description: 'should replace `tick()` with `vi.advanceTimersByTimeAsync(0)`',
2435
input: `
2536
import { tick } from '@angular/core/testing';
2637
27-
tick();
38+
const duration = 0;
39+
tick(duration);
2840
`,
2941
expected: `await vi.advanceTimersByTimeAsync(0);`,
3042
},

0 commit comments

Comments
 (0)