Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/commands/generate/component/common/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { filesystem } from 'gluegun';

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

describe('[Commands: generate common component]', () => {
describe('Commands: [Generate] => [Component] => [Common]', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.setTimeout(100000);
Expand Down Expand Up @@ -47,4 +46,26 @@ describe('[Commands: generate common component]', () => {
expect(ts).toContain(`styleUrls: ['./${name}.component.scss']`);
filesystem.remove(`${name}`);
});

test('should generate a common component with spec file', async () => {
const name = 'sample-style-template-url';
await runNgxdCLI(`g c c ${name}`);

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

expect(ts).toBeDefined();

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

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

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

expect(ts).not.toContain(`OnInit`);

filesystem.remove(`${name}`);
});
});
16 changes: 12 additions & 4 deletions src/commands/generate/component/common/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { GluegunCommand, GluegunToolbox, strings } from 'gluegun';

import {
getComponentName, getComponentPath, printCreated
} from '../../../../utils/functions.helper';
import { getComponentName, getComponentPath, printCreated } from '../../../../utils/functions.helper';

const COMMAND: GluegunCommand = {
name: 'common',
Expand Down Expand Up @@ -38,8 +35,19 @@ const COMMAND: GluegunCommand = {
}
});

template.generate({
template: 'component.template.spec.ts.ejs',
target: `${componentPath}.component.spec.ts`,
props: {
type: 'component',
name: componentName,
...strings
}
});

printCreated(print, `${componentPath}.component.html`);
printCreated(print, `${componentPath}.component.scss`);
printCreated(print, `${componentPath}.component.spec.ts`);
printCreated(print, `${componentPath}.component.ts`);
}
};
Expand Down
24 changes: 24 additions & 0 deletions src/templates/component.template.spec.ts.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { <%= pascalCase(props.name) %> } from './<%= kebabCase(props.name) %>.component';

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

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

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

it('should create <%= kebabCase(props.name) %>', () => {
expect(component).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion src/templates/component.template.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
templateUrl: './<%= kebabCase(props.name) %>.<%= kebabCase(props.type) %>.html',
Expand Down