财产' createAsync'在类型' TestBed'上不存在

时间:2016-09-11 22:39:42

标签: angular jasmine karma-jasmine angular-rc5

我使用angular2-cli创建项目,这个spec文件由cli为我的一个组件自动生成。我将我的应用程序升级到rc4,从那时起,当我运行此测试文件时,我遇到了这个问题。以下是规范文件:

import {
inject, ComponentFixture, TestBed
} from '@angular/core/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { MockComponent } from './mock.component';

describe('Component: Mock', () => {
let builder: TestBed;

beforeEachProviders(() => [MockComponent]);
beforeEach(inject([TestComponentBuilder], function (tcb:  TestComponentBuilder) {
builder = tcb;
}));

 it('should inject the component', inject([MockComponent],
  (component: MockComponent) => {
expect(component).toBeTruthy();
}));

it('should create the component', inject([], () => {
return builder.createAsync(MockComponentTestController)
  .then((fixture: ComponentFixture<any>) => {
    let query = fixture.debugElement.query(By.directive(MockComponent));
    expect(query).toBeTruthy();
    expect(query.componentInstance).toBeTruthy();
  });
}));
});

@Component({
selector: 'test',
template: `
<test></test>
`,
directives: [MockComponent]
})
class MockComponentTestController {
}

上面的规范文件在&#39; createAsync&#39;上引发了错误,我非常确定TestBed上不存在createAsync,但是我用TestBed替换了TestComponentBuilder(在rc4中不推荐使用TestComponentBuilder)。请提供有关如何解决此问题的建议。

1 个答案:

答案 0 :(得分:1)

应为createComponent

fixture = TestBed.createComponent(AppComponent);
let comp = fixture.componentInstance;