Skip to content

Commit 63720c2

Browse files
dev-cristhiangleisonkz
authored andcommitted
✨ feat: create spec file for common component
1 parent 17697c7 commit 63720c2

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

src/commands/generate/component/common/common.test.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { filesystem } from 'gluegun';
2-
32
import { runNgxdCLI } from '../../../../utils/cli-test-setup';
43

5-
describe('[Commands: generate common component]', () => {
4+
describe('Commands: [Generate] => [Component] => [Common]', () => {
65
beforeEach(() => {
76
jest.useFakeTimers();
87
jest.setTimeout(100000);
@@ -47,4 +46,26 @@ describe('[Commands: generate common component]', () => {
4746
expect(ts).toContain(`styleUrls: ['./${name}.component.scss']`);
4847
filesystem.remove(`${name}`);
4948
});
49+
50+
test('should generate a common component with spec file', async () => {
51+
const name = 'sample-style-template-url';
52+
await runNgxdCLI(`g c c ${name}`);
53+
54+
const ts = filesystem.read(`${name}/${name}.component.spec.ts`);
55+
56+
expect(ts).toBeDefined();
57+
58+
filesystem.remove(`${name}`);
59+
});
60+
61+
test('should not contain ngOnInit on import statment', async () => {
62+
const name = 'sample-style-template-url';
63+
await runNgxdCLI(`g c c ${name}`);
64+
65+
const ts = filesystem.read(`${name}/${name}.component.ts`);
66+
67+
expect(ts).not.toContain(`OnInit`);
68+
69+
filesystem.remove(`${name}`);
70+
});
5071
});

src/commands/generate/component/common/common.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { GluegunCommand, GluegunToolbox, strings } from 'gluegun';
2-
3-
import {
4-
getComponentName, getComponentPath, printCreated
5-
} from '../../../../utils/functions.helper';
2+
import { getComponentName, getComponentPath, printCreated } from '../../../../utils/functions.helper';
63

74
const COMMAND: GluegunCommand = {
85
name: 'common',
@@ -38,8 +35,19 @@ const COMMAND: GluegunCommand = {
3835
}
3936
});
4037

38+
template.generate({
39+
template: 'component.template.spec.ts.ejs',
40+
target: `${componentPath}.component.spec.ts`,
41+
props: {
42+
type: 'component',
43+
name: componentName,
44+
...strings
45+
}
46+
});
47+
4148
printCreated(print, `${componentPath}.component.html`);
4249
printCreated(print, `${componentPath}.component.scss`);
50+
printCreated(print, `${componentPath}.component.spec.ts`);
4351
printCreated(print, `${componentPath}.component.ts`);
4452
}
4553
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { <%= pascalCase(props.name) %> } from './<%= kebabCase(props.name) %>.component';
3+
4+
describe('<%= pascalCase(props.name) %>', () => {
5+
let component: <%= pascalCase(props.name) %>;
6+
let fixture: ComponentFixture<<%= pascalCase(props.name) %>>;
7+
8+
beforeEach(async () => {
9+
await TestBed.configureTestingModule({
10+
declarations: [ <%= pascalCase(props.name) %> ]
11+
})
12+
.compileComponents();
13+
});
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(<%= pascalCase(props.name) %>);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create <%= kebabCase(props.name) %>', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});

src/templates/component.template.ts.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22

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

0 commit comments

Comments
 (0)