diff --git a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts index eb58a7f9d5b9..9608a5e931f5 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts @@ -54,11 +54,19 @@ export function transformPending( node: ts.Node, { sourceFile, reporter, tsContext }: RefactorContext, ): ts.Node { - if ( - !ts.isCallExpression(node) || - !ts.isIdentifier(node.expression) || - node.expression.text !== 'it' - ) { + if (!ts.isCallExpression(node)) { + return node; + } + + // `fit`/`xit` have already become `it.only`/`it.skip` when this transformer runs, + // as `transformFocusedAndSkippedTests` is applied earlier in the pipeline. + const isBareIt = ts.isIdentifier(node.expression) && node.expression.text === 'it'; + const isFocusedOrSkippedIt = + ts.isPropertyAccessExpression(node.expression) && + ts.isIdentifier(node.expression.expression) && + node.expression.expression.text === 'it' && + (node.expression.name.text === 'only' || node.expression.name.text === 'skip'); + if (!isBareIt && !isFocusedOrSkippedIt) { return node; } @@ -100,7 +108,9 @@ export function transformPending( return node; } - const newExpression = createPropertyAccess(node.expression, 'skip'); + // A pending spec never runs its body in Jasmine, even when focused, so `it.only` + // also becomes `it.skip`. + const newExpression = createPropertyAccess('it', 'skip'); const newTestFn = ts.isArrowFunction(testFn) ? ts.factory.updateArrowFunction( testFn, diff --git a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts index 611bb2330cd3..d8fb576948ce 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts @@ -210,6 +210,34 @@ describe('transformPending', () => { }); `, }, + { + description: 'should transform a focused test (fit) with pending() to it.skip()', + input: ` + fit('is a work in progress', () => { + pending('Not yet implemented'); + }); + `, + expected: ` + it.skip('is a work in progress', () => { + // TODO: vitest-migration: The pending() function was converted to a skipped test (\`it.skip\`). See: https://vitest.dev/api/vi.html#it-skip + // pending('Not yet implemented'); + }); + `, + }, + { + description: 'should comment out pending() in a skipped test (xit)', + input: ` + xit('is a work in progress', () => { + pending('Not yet implemented'); + }); + `, + expected: ` + it.skip('is a work in progress', () => { + // TODO: vitest-migration: The pending() function was converted to a skipped test (\`it.skip\`). See: https://vitest.dev/api/vi.html#it-skip + // pending('Not yet implemented'); + }); + `, + }, ]; testCases.forEach(({ description, input, expected }) => {