0

我正在使用 angular2-cli 创建项目,并且此规范文件由 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 {
}

上面的规范文件在“createAsync”上引发错误,我很确定 TestBed 上不存在 createAsync 但我用 TestBed 替换了 TestComponentBuilder(TestComponentBuilder 在 rc4 中已被弃用)。请提供有关如何解决此问题的建议。

4

1 回答 1

1

它应该是createComponent

fixture = TestBed.createComponent(AppComponent);
let comp = fixture.componentInstance;
于 2016-09-12T04:58:42.757 回答