如何使测试通过Angular 6

时间:2018-12-13 08:47:32

标签: javascript angular unit-testing

我创建了一个angular 6项目,然后将其与下载的模板合并,当我尝试将这些更改推送到VSTS(AzureDevOps)时,构建失败,当我检查错误时,这是​​与angular的单元测试有关的问题不断失败,然后,当我运行此命令时,我被要求运行此命令npm run test:ci,但我对已创建的组件的测试失败。我是单元测试的新手,我收到的错误是“未在jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时内调用异步回调。

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

import { AdvertComponent } from './advert.component';

describe('AdvertComponent', () => {
  let component: AdvertComponent;
  let fixture: ComponentFixture<AdvertComponent>;
  var originalTimeout;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ AdvertComponent ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(AdvertComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  beforeEach(async() => {
    originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
  });

  afterEach(async() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
  });
});

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

import { SidebarComponent } from './sidebar.component';

describe('SidebarComponent', () => {
  let component: SidebarComponent;
  let fixture: ComponentFixture<SidebarComponent>;
  var originalTimeout;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ SidebarComponent ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(SidebarComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  beforeEach(async() => {
    originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
  });

  afterEach(async() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
  });
});

0 个答案:

没有答案