角度2组件的测试不起作用

时间:2017-06-15 05:05:47

标签: angular unit-testing karma-jasmine

由于我是角色2的新手,我从git https://github.com/AngularClass/angular-starter

克隆了一个项目

并对其进行更改。 我添加了文件夹横幅和三个文件,并在app.module.ts,app.component.ts和app.route.ts中进行相应的更改。

        banner (folder name)

        banner.component.ts

    import { Component } from '@angular/core';

    @Component({
      selector: 'app-banner',
      template: '<h1>{{title}}</h1>'
    })
    export class BannerComponent {
     public title = 'Test Tour of Heroes';
    }
        banner.component.spec.ts

    import { ComponentFixture, TestBed } from '@angular/core/testing';
    import { By } from '@angular/platform-browser';
    import { DebugElement } from '@angular/core';
    import { BannerComponent } from './banner.component';

    describe('BannerComponent', () => {

      let comp: BannerComponent;
      let fixture: ComponentFixture<BannerComponent>;
      let de: DebugElement;
      let el: HTMLElement;

      beforeEach(() => {
        TestBed.configureTestingModule({
          declarations: [ BannerComponent ], // declare the test component
        });

        fixture = TestBed.createComponent(BannerComponent);

        comp = fixture.componentInstance; // BannerComponent test instance

        // query for the title <h1> by CSS element selector
        de = fixture.debugElement.query(By.css('h1'));
        el = de.nativeElement;
      });
    });

        index.ts
    export * from './banner.component';

当我通过npm start命令运行项目时,它会显示组件,但是当我使用npm test时,它不会测试我的模块。我根据惯例命名了我的测试。 所以请帮助测试我的模块。

0 个答案:

没有答案