Skip to content

Commit 15d2650

Browse files
committed
fix(migrations): fix bug in ngclass-to-class migration
Fix bug in ngclass-to-class migration. The migrateSpaceSeparatedKey option was configured incorrectly and I added a test case
1 parent bacda4f commit 15d2650

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/core/schematics/migrations/ngclass-to-class-migration/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"type": "boolean",
1515
"description": "Enables the migration of object literals with space-separated keys",
1616
"x-prompt": "Should the migration also migrate space-separated keys?",
17-
"default": "false"
17+
"default": false
1818
}
1919
}
2020
}

packages/core/schematics/test/ngclass_to_class_migration_spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,28 @@ describe('NgClass migration', () => {
229229
const content = tree.readContent('/app.component.ts');
230230
expect(content).toContain('<div [class]=""></div>');
231231
});
232+
233+
it('should not split and migrate multiple classes in one key without option', async () => {
234+
writeFile(
235+
'/app.component.ts',
236+
`
237+
import {Component} from '@angular/core';
238+
import {NgClass} from '@angular/common';
239+
@Component({
240+
imports: [NgClass],
241+
template: \`
242+
<div [ngClass]="{'class1 class2': condition}"></div>
243+
\` })
244+
export class Cmp {}
245+
`,
246+
);
247+
248+
await runMigration();
249+
250+
const content = tree.readContent('/app.component.ts');
251+
252+
expect(content).toContain(`<div [ngClass]="{'class1 class2': condition}"></div>`);
253+
});
232254
});
233255

234256
describe('Simple ngClass object migrations', () => {

0 commit comments

Comments
 (0)