Angular 2和核心测试都是新手。
我有一个使用注入的MovieService的MovieComponent。试图学习,所以使用路线参数。代码正在按预期工作。
describe('MovieComponent', () => {
let component: MovieComponent;
let fixture: ComponentFixture<MovieComponent>;
let options: RequestOptions;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MovieComponent ],
imports: [
HttpModule
],
providers: [
{
provide: ActivatedRoute, useValue: {
params: Observable.of({ movieName: 'Bah' })
}
}, MovieService, Http, {provide: ConnectionBackend},
],
schemas :[NO_ERRORS_SCHEMA ]
})
.compileComponents();
}));
beforeEach(() => {
options = new RequestOptions({method: RequestMethod.Get});
fixture = TestBed.createComponent(MovieComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
但是,我收到了这个测试错误:
TypeError: Cannot read property 'getMovies' of undefined
提前致谢。
答案 0 :(得分:0)
您是否在编译器中运行它?它编译?我不这么认为
onActivityResult
是对的。只需传递MovieService,如下所示:`
^([0-9]+y\s?)?(((1[0-2])|([1-9]))m\s?)?((([12]?[0-9])|(3[01]))d)?$
`