【发布时间】:2016-04-06 14:45:00
【问题描述】:
我正在尝试进行 Angular 2.0 组件测试。我使用this 帖子作为参考(Angular 2.0 dos 中还没有参考)。
这是我的测试:
import 'reflect-metadata';
import {
it,
describe,
expect,
inject,
injectAsync,
beforeEach,
beforeEachProviders,
TestComponentBuilder,
ComponentFixture
} from 'angular2/testing';
import {Main} from './index';
describe('Main', () => {
// provide our implementations or mocks to the dependency injector
beforeEachProviders(() => [
Main
]);
it('should have title', inject([ Main ], (main) => {
expect(main.title).toEqual('Hello Angular 2.0');
}));
it('should add item to list', injectAsync([TestComponentBuilder, Main], (tcb: TestComponentBuilder, main) => {
return tcb.createAsync(Main).then((componentFixture: ComponentFixture) => {
const element = componentFixture.nativeElement;
expect(element.querySelectorAll('input').length).toBe(1);
});
}));
})
现在,我在运行这些测试时收到Cannot resolve all parameters for 'TestComponentBuilder' 错误。尝试将 TestComponentBuilder 添加到 beforeEachProviders 结果却出现不同的错误:
Cannot resolve all parameters for 'TestComponentBuilder'(?).
我做错了什么?
【问题讨论】:
标签: javascript unit-testing angular