Skip to content

Commit cf3cb2e

Browse files
gauravsoni119alan-agius4
authored andcommitted
fix(@schematics/angular): fix extra comma added when use --change-detection=onPush and --style=none to generate a component
(cherry picked from commit a5e9976)
1 parent 4cd2331 commit cf3cb2e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }
66
<p>
77
<%= dasherize(name) %> works!
88
</p>
9-
`,<% } else { %>
10-
templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.html',<% } if(inlineStyle) { %>
9+
`<% } else { %>
10+
templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.html'<% } if(inlineStyle) { %>,
1111
styles: [<% if(displayBlock){ %>
1212
`
1313
:host {
1414
display: block;
1515
}
1616
`<% } %>
17-
]<% } else if (style !== 'none') { %>
17+
]<% } else if (style !== 'none') { %>,
1818
styleUrls: ['./<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
1919
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
2020
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>

packages/schematics/angular/component/index_spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,27 @@ describe('Component Schematic', () => {
397397
);
398398
expect(tree.files).not.toContain('/projects/bar/src/app/foo/foo.component.spec.ts');
399399
});
400+
401+
it('should respect templateUrl when style=none and changeDetection=OnPush', async () => {
402+
const options = { ...defaultOptions, style: Style.None, changeDetection: 'OnPush' };
403+
const tree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise();
404+
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
405+
expect(content).not.toMatch(/styleUrls: /);
406+
expect(content).toMatch(/templateUrl: '.\/foo.component.html',\n/);
407+
expect(content).toMatch(/changeDetection: ChangeDetectionStrategy.OnPush/);
408+
});
409+
410+
it('should respect inlineTemplate when style=none and changeDetection=OnPush', async () => {
411+
const options = {
412+
...defaultOptions,
413+
style: Style.None,
414+
changeDetection: 'OnPush',
415+
inlineTemplate: true,
416+
};
417+
const tree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise();
418+
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
419+
expect(content).not.toMatch(/styleUrls: /);
420+
expect(content).toMatch(/template: `(\n(.|)*){3}\n\s*`,\n/);
421+
expect(content).toMatch(/changeDetection: ChangeDetectionStrategy.OnPush/);
422+
});
400423
});

0 commit comments

Comments
 (0)