Skip to content

Commit 2312b48

Browse files
committed
🧪 test(commands): test cases for api and common service
1 parent e5c4d8e commit 2312b48

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { filesystem } from 'gluegun';
2+
3+
import { runNgxdCLI } from '../../../../utils/cli-test-setup';
4+
5+
describe('Commands: [Generate] => [Service] => [Api]', () => {
6+
const name = 'gsc';
7+
8+
beforeEach(() => {
9+
jest.useFakeTimers();
10+
jest.setTimeout(100000);
11+
});
12+
13+
afterEach(() => {
14+
jest.clearAllTimers();
15+
});
16+
17+
test('should generate a api service with 2 files', async () => {
18+
await runNgxdCLI(`g s a ${name}`);
19+
20+
const ts = filesystem.read(`${name}/${name}.api.ts`);
21+
const spec = filesystem.read(`${name}/${name}.api.spec.ts`);
22+
23+
expect(ts).toBeDefined();
24+
expect(spec).toBeDefined();
25+
filesystem.remove(`${name}`);
26+
});
27+
28+
test('should generate a api service with correct content ', async () => {
29+
const name = 'fruit';
30+
31+
await runNgxdCLI(`g s a ${name}`);
32+
33+
const ts = filesystem.read(`${name}/${name}.api.ts`);
34+
const spec = filesystem.read(`${name}/${name}.api.spec.ts`);
35+
36+
expect(ts).toContain(`import { Injectable } from '@angular/core'`);
37+
expect(ts).toContain(`@Injectable({`);
38+
expect(ts).toContain(`providedIn: 'root'`);
39+
expect(ts).toContain(`export class FruitApi {`);
40+
41+
expect(spec).toContain("describe('FruitApi', () => {");
42+
expect(spec).toContain("it('should be created', () => {");
43+
expect(spec).toContain('service = TestBed.inject(FruitApi);');
44+
45+
filesystem.remove(`${name}`);
46+
});
47+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { filesystem } from 'gluegun';
2+
3+
import { runNgxdCLI } from '../../../../utils/cli-test-setup';
4+
5+
describe('Commands: [Generate] => [Service] => [Common]', () => {
6+
const name = 'gsc';
7+
8+
beforeEach(() => {
9+
jest.useFakeTimers();
10+
jest.setTimeout(100000);
11+
});
12+
13+
afterEach(() => {
14+
jest.clearAllTimers();
15+
});
16+
17+
test('should generate a common service with 2 files', async () => {
18+
await runNgxdCLI(`g s c ${name}`);
19+
20+
const ts = filesystem.read(`${name}/${name}.service.ts`);
21+
const spec = filesystem.read(`${name}/${name}.service.spec.ts`);
22+
23+
expect(ts).toBeDefined();
24+
expect(spec).toBeDefined();
25+
filesystem.remove(`${name}`);
26+
});
27+
28+
test('should generate a common service with correct content ', async () => {
29+
const name = 'fruit';
30+
31+
await runNgxdCLI(`g s c ${name}`);
32+
33+
const ts = filesystem.read(`${name}/${name}.service.ts`);
34+
const spec = filesystem.read(`${name}/${name}.service.spec.ts`);
35+
36+
expect(ts).toContain(`import { Injectable } from '@angular/core'`);
37+
expect(ts).toContain(`@Injectable({`);
38+
expect(ts).toContain(`providedIn: 'root'`);
39+
expect(ts).toContain(`export class FruitService {`);
40+
41+
expect(spec).toContain("describe('FruitService', () => {");
42+
expect(spec).toContain("it('should be created', () => {");
43+
expect(spec).toContain('service = TestBed.inject(FruitService);');
44+
45+
filesystem.remove(`${name}`);
46+
});
47+
});

0 commit comments

Comments
 (0)