@select()
デコレータに依存するAngularでコンポーネントをテストする場合、私はMockNgRedux.getSelectorStub('myStoreProperty').next(testState)
を使用して新しい値をサブスクライバに送信しますが、次の関数を呼び出すと、新しい価値を持つサブスクリプション。@ angle-redux/storeで@selectデコレータをテストする
のコード例を参照してください:ここで
export class BasicInfoComponent {
@select() application$: Observable<Application>;
this.application$.subscribe((app: Application) => {
//... this code is never triggered.
}
}
は、コンポーネントが作成されている前にあなたがMockNgRedux.reset()
を呼び出す必要があり、テスト・セットアップ
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();
});