/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { SchematicTestRunner, UnitTestTree } from "@angular-devkit/schematics/testing"; import { Schema as WorkspaceOptions } from "@schematics/angular/workspace/schema"; import { Schema as ApplicationOptions } from "@schematics/angular/application/schema"; const collectionPath = require.resolve("../collection.json"); describe("form", () => { const testRunner = new SchematicTestRunner("schematics", collectionPath); const workspaceOptions: WorkspaceOptions = { name: "example", version: "6.0.0", }; describe("example project", () => { const appOptions: ApplicationOptions = { name: "example", inlineStyle: false, inlineTemplate: false, routing: false, skipTests: false, skipPackageJson: false }; let appTree: UnitTestTree; beforeEach(() => { appTree = testRunner.runExternalSchematic("@schematics/angular", "workspace", workspaceOptions); appTree = testRunner.runExternalSchematic("@schematics/angular", "application", appOptions, appTree); }); it('should create a form component', async () => { const options = {...appOptions}; const tree = await testRunner.runSchematicAsync('form', {...options, name: 'product/product-add', project: options.name}, appTree).toPromise(); expect(tree.files).toEqual( jasmine.arrayContaining([ "/example/src/app/product/product-add/product-add.component.css", "/example/src/app/product/product-add/product-add.component.html", "/example/src/app/product/product-add/product-add.component.ts", ])); }); it('should find the closest module', () => { const options = { ...appOptions }; const productModule = "/example/src/app/product/product.module.ts"; appTree.create(productModule, ` import { NgModule } from '@angular/core'; @NgModule({ imports: [], declarations: [] }) export class ProductModule { } `); const tree = testRunner.runSchematic('form', { ...options, name: 'product/product-add', project: options.name }, appTree); const productModuleContent = tree.readContent(productModule); expect(productModuleContent).toMatch("import { ProductAddComponent } from './product-add/product-add.component'"); }); it('should set the entry component', () => { const options = { ...appOptions, entryComponent: true }; const tree = testRunner.runSchematic('form', { ...options, name: 'product/product-add', project: options.name }, appTree); const appModuleContent = tree.readContent('/example/src/app/app.module.ts'); expect(appModuleContent).toMatch(/entryComponents: \[ProductAddComponent\]/); }); }); });