Skip to content

Commit

Permalink
fix(angular): style=none should not create file #18785 (#18836)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 authored Aug 25, 2023
1 parent b9eba9d commit 577f820
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions packages/angular/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,51 @@ describe('component Generator', () => {
);
});

it('should not create a style file when --style=none', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
addProjectConfiguration(tree, 'lib1', {
projectType: 'library',
sourceRoot: 'libs/lib1/src',
root: 'libs/lib1',
});
tree.write(
'libs/lib1/src/lib/lib.module.ts',
`
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
exports: []
})
export class LibModule {}`
);
tree.write('libs/lib1/src/index.ts', '');

// ACT
await componentGenerator(tree, {
name: 'example',
project: 'lib1',
style: 'none',
});

// ASSERT
expect(
tree.exists('libs/lib1/src/lib/example/example.component.none')
).toBeFalsy();
expect(tree.read('libs/lib1/src/lib/example/example.component.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { Component } from '@angular/core';
@Component({
selector: 'proj-example',
templateUrl: './example.component.html',
})
export class ExampleComponent {}
"
`);
});

it('should create the component correctly and export it in the entry point when "export=true"', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function componentGenerator(tree: Tree, rawOptions: Schema) {
tree.delete(pathToTemplateFile);
}

if (options.inlineStyle) {
if (options.style === 'none' || options.inlineStyle) {
const pathToStyleFile = joinPathFragments(
options.directory,
`${componentNames.fileName}.${typeNames.fileName}.${options.style}`
Expand Down

0 comments on commit 577f820

Please sign in to comment.