0

我有一个测试文件夹,其中有 3 个文件,

1)nav-bar.init.spec.ts
2)nav-bar.scaffold.ts
3)nav-bar.spec.ts

我分别有以下代码,

在 nav-bar.init.spec.ts 中,

       import { TestBed, async } from '@angular/core/testing';
       import { Navbarcomponent } from './app.component';
        describe('Navbarcomponent', () => {
          beforeEach(async(() => {
                TestBed.configureTestingModule({
              declarations: [
             Navbarcomponent
                ],
              }).compileComponents();
              }));

在 nav-bar.spec.ts 中,

       import { TestBed, async } from'@angular/core/testing';
       import { Navbarcomponent } from './app.component';
        describe('Navbarcomponent', () => {
           let component: Navbarcomponent;
          beforeEach(() => {
                  component = new Navbarcomponent();
           }));
        it (should create,()=>{
            expect(conponent).toBeTruthy()
        });                 //// I added this test case here

当我运行测试用例时,业力屏幕显示“NO SPEC FOUND”

我的 Karma.config 文件, karma-config-1

 [karma-config-2][2]

我对这种模块化感到困惑。任何人都可以请建议我帮助。谢谢。

4

1 回答 1

0

快速浏览一下,我认为问题在于您没有正确配置测试平台:

import { ComponentFixture, TestBed } from '@angular/core/testing';

describe('AppComponent', () => {
  let component: AppComponent;
  let fixture: ComponentFixture<AppComponent>;

TestBed.configureTestingModule({
      schemas: [NO_ERRORS_SCHEMA],
      declarations: [AppComponent],
      providers: [
        { provide: Router, useValue: routerStub },
        { provide: ActivatedRoute, useValue: activatedRouteStub },
        { provide: I18nService, useValue: i18nServiceStub },
        { provide: PlatformLocation, useValue: platformLocationStub },
        ...
      ]
    });

    fixture = TestBed.createComponent(AppComponent);
    component = fixture.componentInstance;
});
于 2019-08-20T10:21:05.867 回答