/** * @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("table", () => { 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 table component', async () => { const options = {...appOptions}; const tree = await testRunner.runSchematicAsync('table', {...options, name: 'product/product', project: options.name}, appTree).toPromise(); expect(tree.files).toEqual( jasmine.arrayContaining([ "/example/src/app/product/product-list/product-list.component.css", "/example/src/app/product/product-list/product-list.component.html", "/example/src/app/product/product-list/product-list.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('table', { ...options, name: 'product/product', project: options.name }, appTree); const productModuleContent = tree.readContent(productModule); expect(productModuleContent).toMatch("import { ProductListComponent } from './product-list/product-list.component'"); }); }); });