Skip to content

Commit c800122

Browse files
committed
fix(@schematics/angular): fix browserMode option mapping in refactor-jasmine-vitest
The jasmine-vitest refactor schematic previously mapped the `browserMode` option to `options.browerMode` (with a spelling typo). Because of the index signature `[property: string]: any` in the generated options Schema type, the compiler did not emit any error, which resulted in the option silently resolving to `undefined` at runtime and disabling browser-mode transformations. (cherry picked from commit 21cb628)
1 parent 979b781 commit c800122

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

packages/schematics/angular/refactor/jasmine-vitest/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default function (options: Schema): Rule {
121121
const content = tree.readText(file);
122122
const newContent = transformJasmineToVitest(file, content, reporter, {
123123
addImports: !!options.addImports,
124-
browserMode: !!options.browerMode,
124+
browserMode: !!options.browserMode,
125125
fakeAsync: !!options.fakeAsync,
126126
});
127127

packages/schematics/angular/refactor/jasmine-vitest/index_spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,46 @@ describe('Jasmine to Vitest Schematic', () => {
238238
expect(logs).toContain('- 1 TODO(s) added for manual review:');
239239
expect(logs).toContain(' - 1x spyOnAllFunctions');
240240
});
241+
242+
it('should not transform toHaveClass when browserMode is true', async () => {
243+
const specFilePath = 'projects/bar/src/app/app.spec.ts';
244+
const content = `
245+
describe('AppComponent', () => {
246+
it('should check class', () => {
247+
expect(element).toHaveClass('active');
248+
});
249+
});
250+
`;
251+
appTree.overwrite(specFilePath, content);
252+
253+
const tree = await schematicRunner.runSchematic(
254+
'refactor-jasmine-vitest',
255+
{ project: 'bar', browserMode: true },
256+
appTree,
257+
);
258+
259+
const result = tree.readContent(specFilePath);
260+
expect(result).toContain("expect(element).toHaveClass('active');");
261+
});
262+
263+
it('should transform toHaveClass when browserMode is false', async () => {
264+
const specFilePath = 'projects/bar/src/app/app.spec.ts';
265+
const content = `
266+
describe('AppComponent', () => {
267+
it('should check class', () => {
268+
expect(element).toHaveClass('active');
269+
});
270+
});
271+
`;
272+
appTree.overwrite(specFilePath, content);
273+
274+
const tree = await schematicRunner.runSchematic(
275+
'refactor-jasmine-vitest',
276+
{ project: 'bar', browserMode: false },
277+
appTree,
278+
);
279+
280+
const result = tree.readContent(specFilePath);
281+
expect(result).toContain("expect(element.classList.contains('active')).toBe(true);");
282+
});
241283
});

0 commit comments

Comments
 (0)