【发布时间】:2017-11-08 17:59:46
【问题描述】:
在 Angular 中测试依赖于 @select() 装饰器的组件时,我使用 MockNgRedux.getSelectorStub('myStoreProperty').next(testState) 向订阅者发送新值,但是当我调用下一个函数时,它不会触发具有新值的订阅。
查看示例代码:
export class BasicInfoComponent {
@select() application$: Observable<Application>;
this.application$.subscribe((app: Application) => {
//... this code is never triggered.
}
}
这是测试设置
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BasicInfoComponent],
imports: [
NgReduxTestingModule,
ReactiveFormsModule
],
providers: [
//... providers
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BasicInfoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
MockNgRedux.reset();
});
afterEach(() => {
fixture.destroy();
});
【问题讨论】:
标签: angular unit-testing testing redux