Skip to content

refactor-jasmine-vitest: createSpyObj without base name not handled #31941

@jase88

Description

@jase88

Command

generate

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

refactor-jasmine-vitest skips createSpyObjs if they are only providing one argument. The test are hinting that a call like jasmine.createSpyObj('MyService') is not handlable.

But the first argument doesn't have to be a base name. In fact it is optional

createSpyObj(baseName (opt), methodNames, propertyNames (opt)), see https://jasmine.github.io/api/5.12/jasmine.html

Currently something like

const loggerSpy = jasmine.createSpyObj<LoggingService>(['error']);

is transformed to

// TODO: vitest-migration: jasmine.createSpyObj called with a single argument is not supported for transformation. See: https://vitest.dev/api/vi.html#vi-fn
const loggerSpy = jasmine.createSpyObj<LoggingService>(['error']);

expected output:

const loggerSpy = { error: vi.fn() };

Minimal Reproduction

example spec file:

describe('Foo', () => {
 let loggerSpy: jasmine.SpyObj<LoggingService>;

  beforeEach(() => {
    loggerSpy = jasmine.createSpyObj<LoggingService>(['error']);
  });

  it('should be fine', () => {
    expect(loggerSpy).toBeTruthy();
  });
});

Exception or Error


Your Environment

Angular CLI       : 21.0.0
Angular           : 21.0.0
Node.js           : 25.1.0 (Unsupported)
Package Manager   : npm 11.6.3
Operating System  : darwin arm64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                           │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/core              │ 21.0.0            │ 21.0.0            │
│ @angular/build                    │ 21.0.0            │ ^21.0.0           │
│ @angular/cdk                      │ 21.0.0            │ 21.0.0            │
│ @angular/cli                      │ 21.0.0            │ 21.0.0            │
│ @angular/common                   │ 21.0.0            │ 21.0.0            │
│ @angular/compiler                 │ 21.0.0            │ 21.0.0            │
│ @angular/compiler-cli             │ 21.0.0            │ 21.0.0            │
│ @angular/core                     │ 21.0.0            │ 21.0.0            │
│ @angular/forms                    │ 21.0.0            │ 21.0.0            │
│ @angular/platform-browser         │ 21.0.0            │ 21.0.0            │
│ @angular/platform-browser-dynamic │ 21.0.0            │ 21.0.0            │
│ @angular/router                   │ 21.0.0            │ 21.0.0            │
│ rxjs                              │ 7.8.2             │ 7.8.2             │
│ typescript                        │ 5.9.3             │ 5.9.3             │
└───────────────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions