Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/schematics/angular/refactor/jasmine-vitest/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Jasmine to Vitest Schematic', () => {
);

const newContent = tree.readContent(specFilePath);
expect(newContent).toContain(`vi.spyOn(service, 'myMethod');`);
expect(newContent).toContain(`vi.spyOn(service, 'myMethod').mockReturnValue(undefined);`);
});

it('should only transform files matching the fileSuffix option', async () => {
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Jasmine to Vitest Schematic', () => {
expect(unchangedContent).not.toContain(`vi.spyOn(window, 'alert');`);

const changedContent = tree.readContent(testFilePath);
expect(changedContent).toContain(`vi.spyOn(window, 'confirm');`);
expect(changedContent).toContain(`vi.spyOn(window, 'confirm').mockReturnValue(undefined);`);
});

it('should print verbose logs when the verbose option is true', async () => {
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('Jasmine to Vitest Schematic', () => {
);

const changedContent = tree.readContent('projects/bar/src/app/nested/nested.spec.ts');
expect(changedContent).toContain(`vi.spyOn(window, 'confirm');`);
expect(changedContent).toContain(`vi.spyOn(window, 'confirm').mockReturnValue(undefined);`);

const unchangedContent = tree.readContent('projects/bar/src/app/app.spec.ts');
expect(unchangedContent).toContain(`spyOn(window, 'alert');`);
Expand All @@ -158,7 +158,7 @@ describe('Jasmine to Vitest Schematic', () => {
);

const changedContent = tree.readContent('projects/bar/src/app/nested/nested.spec.ts');
expect(changedContent).toContain(`vi.spyOn(window, 'confirm');`);
expect(changedContent).toContain(`vi.spyOn(window, 'confirm').mockReturnValue(undefined);`);

const unchangedContent = tree.readContent('projects/bar/src/app/app.spec.ts');
expect(unchangedContent).toContain(`spyOn(window, 'alert');`);
Expand All @@ -177,10 +177,12 @@ describe('Jasmine to Vitest Schematic', () => {
);

const changedAppContent = tree.readContent('projects/bar/src/app/app.spec.ts');
expect(changedAppContent).toContain(`vi.spyOn(window, 'alert');`);
expect(changedAppContent).toContain(`vi.spyOn(window, 'alert').mockReturnValue(undefined);`);

const changedNestedContent = tree.readContent('projects/bar/src/app/nested/nested.spec.ts');
expect(changedNestedContent).toContain(`vi.spyOn(window, 'confirm');`);
expect(changedNestedContent).toContain(
`vi.spyOn(window, 'confirm').mockReturnValue(undefined);`,
);

const unchangedContent = tree.readContent('projects/bar/src/other/other.spec.ts');
expect(unchangedContent).toContain(`spyOn(window, 'close');`);
Expand All @@ -194,10 +196,12 @@ describe('Jasmine to Vitest Schematic', () => {
);

const changedAppContent = tree.readContent('projects/bar/src/app/app.spec.ts');
expect(changedAppContent).toContain(`vi.spyOn(window, 'alert');`);
expect(changedAppContent).toContain(`vi.spyOn(window, 'alert').mockReturnValue(undefined);`);

const changedNestedContent = tree.readContent('projects/bar/src/app/nested/nested.spec.ts');
expect(changedNestedContent).toContain(`vi.spyOn(window, 'confirm');`);
expect(changedNestedContent).toContain(
`vi.spyOn(window, 'confirm').mockReturnValue(undefined);`,
);
});

it('should throw if the include path does not exist', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Jasmine to Vitest Transformer - Integration Tests', () => {
});
it('should handle user click', () => {
vi.spyOn(window, 'alert');
vi.spyOn(window, 'alert').mockReturnValue(undefined);
const button = fixture.nativeElement.querySelector('button');
button.click();
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Jasmine to Vitest Transformer - addImports option', () => {
const input = `spyOn(foo, 'bar');`;
const expected = `
import { vi } from 'vitest';
vi.spyOn(foo, 'bar');
vi.spyOn(foo, 'bar').mockReturnValue(undefined);
`;
await expectTransformation(input, expected, true);
});
Expand All @@ -27,7 +27,7 @@ describe('Jasmine to Vitest Transformer - addImports option', () => {
import { type Mock, vi } from 'vitest';

let mySpy: Mock;
vi.spyOn(foo, 'bar');
vi.spyOn(foo, 'bar').mockReturnValue(undefined);
`;
await expectTransformation(input, expected, true);
});
Expand All @@ -41,7 +41,7 @@ describe('Jasmine to Vitest Transformer - addImports option', () => {
import type { Mock } from 'vitest';

let mySpy: Mock;
vi.spyOn(foo, 'bar');
vi.spyOn(foo, 'bar').mockReturnValue(undefined);
`;
await expectTransformation(input, expected, false);
});
Expand Down
Loading
Loading