diff --git a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher.ts b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher.ts index 1e0a87dc80f2..c8ba2baadefa 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher.ts @@ -474,15 +474,34 @@ export function transformCalledOnceWith( return node; } + const expectCall = call.expression.expression; + const args = call.arguments; + + // Splitting a negated assertion would assert that neither condition holds instead of not both. + if (ts.isPropertyAccessExpression(expectCall) && expectCall.name.text === 'not') { + reporter.reportTransformation( + sourceFile, + node, + 'Transformed `.not.toHaveBeenCalledOnceWith()` to `.not.toHaveBeenCalledExactlyOnceWith()`.', + ); + + return ts.factory.updateExpressionStatement( + node, + ts.factory.updateCallExpression( + call, + createPropertyAccess(expectCall, 'toHaveBeenCalledExactlyOnceWith'), + call.typeArguments, + args, + ), + ); + } + reporter.reportTransformation( sourceFile, node, 'Transformed `.toHaveBeenCalledOnceWith()` to `.toHaveBeenCalledTimes(1)` and `.toHaveBeenCalledWith()`.', ); - const expectCall = call.expression.expression; - const args = call.arguments; - const timesCall = ts.factory.createCallExpression( createPropertyAccess(expectCall, 'toHaveBeenCalledTimes'), undefined, diff --git a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher_spec.ts b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher_spec.ts index 274202ed1689..f123ac3b84b3 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher_spec.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher_spec.ts @@ -113,6 +113,11 @@ describe('transformCalledOnceWith', () => { expect(mySpy).toHaveBeenCalledWith('foo', 'bar'); `, }, + { + description: 'should transform a negated toHaveBeenCalledOnceWith(...) into a single call', + input: `expect(mySpy).not.toHaveBeenCalledOnceWith('foo');`, + expected: `expect(mySpy).not.toHaveBeenCalledExactlyOnceWith('foo');`, + }, ]; testCases.forEach(({ description, input, expected }) => {