Skip to content

Commit 2a00899

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

2 files changed

Lines changed: 15 additions & 3 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ 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: `
32+
const duration = 100;
33+
await vi.advanceTimersByTimeAsync(duration);
34+
`,
35+
},
2236
{
2337
description: 'should replace `tick()` with `vi.advanceTimersByTimeAsync(0)`',
2438
input: `

0 commit comments

Comments
 (0)