|
| 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