Skip to content

Commit

Permalink
🐛 fix: generate common component interpolated class name
Browse files Browse the repository at this point in the history
  • Loading branch information
gleisonkz committed Jun 1, 2022
1 parent 789e3b9 commit 8f740fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 16 additions & 2 deletions src/commands/generate/component/common/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { filesystem } from 'gluegun';
import { filesystem, strings } from 'gluegun';

import { runNgxdCLI } from '../../../../utils/cli-test-setup';

describe('Commands: [Generate] => [Component] => [Common]', () => {
Expand Down Expand Up @@ -58,7 +59,20 @@ describe('Commands: [Generate] => [Component] => [Common]', () => {
filesystem.remove(`${name}`);
});

test('should not contain ngOnInit on import statment', async () => {
test('should properly interpolate component name on spec file', async () => {
const name = 'sample-style-template-url';
await runNgxdCLI(`g c c ${name}`);

const ts = filesystem.read(`${name}/${name}.component.spec.ts`);

const pascalCaseName = strings.pascalCase(name);

expect(ts).toContain(`describe('${pascalCaseName}Component', () => {`);

filesystem.remove(`${name}`);
});

test('should not contain ngOnInit on import statement', async () => {
const name = 'sample-style-template-url';
await runNgxdCLI(`g c c ${name}`);

Expand Down
12 changes: 6 additions & 6 deletions src/templates/component.template.spec.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { <%= pascalCase(props.name) %> } from './<%= kebabCase(props.name) %>.component';
import { <%= pascalCase(props.name) %>Component } from './<%= kebabCase(props.name) %>.component';

describe('<%= pascalCase(props.name) %>', () => {
let component: <%= pascalCase(props.name) %>;
let fixture: ComponentFixture<<%= pascalCase(props.name) %>>;
describe('<%= pascalCase(props.name) %>Component', () => {
let component: <%= pascalCase(props.name) %>Component;
let fixture: ComponentFixture<<%= pascalCase(props.name) %>Component>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ <%= pascalCase(props.name) %> ]
declarations: [ <%= pascalCase(props.name) %>Component ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(<%= pascalCase(props.name) %>);
fixture = TestBed.createComponent(<%= pascalCase(props.name) %>Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down

0 comments on commit 8f740fe

Please sign in to comment.