Aiguo
Aiguo

Reputation: 3566

Property 'createAsync' does not exist on type 'TestBed'

I'm using angular2-cli to create projects and this spec file is automatically made by cli for one of my component. I upgraded my app to rc4 and since then I've been encountering this issue when I run this test file. Below is the spec file:

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 {
}

The above spec file throws an error on 'createAsync', I'm pretty sure that createAsync does not exist on TestBed but I replaced TestComponentBuilder with TestBed (TestComponentBuilder has been deprecated in rc4). Please provide suggestions on how to resolve this issue.

Upvotes: 0

Views: 2260

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657676

It should be createComponent:

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

Upvotes: 1

Related Questions