如何大理石测试ngrx效果

时间:2018-04-26 01:01:50

标签: unit-testing ngrx-effects

我有以下ngrx效果

@Injectable()
export class StoreEffects {
    constructor(
        private store: Store<State>,
        private actions$: Actions,
    ) { }

@Effect()
userProfile$ = this.actions$
    .ofType('Load')
    .switchMap(action => {
        const payLoad = action['payload'];

        //Run code to load here

        return Observable.of({});  //Just for clarity I have simplified
    });
}

现在我想对此进行单元测试,并且遇到了以下文档

https://github.com/ngrx/platform/blob/master/docs/effects/testing.md

通过遵循文档,我提出了以下规范

beforeEach(() => {
    TestBed.configureTestingModule({
        imports: [
            HttpClientModule,
            StoreModule.forRoot({}) //I'm not sure why you need this, but if I dont supply this it does not work
        ],
        providers: [
            ProfileEffects,
            provideMockActions(() => actions),               
        ],
    });
});

it('should work', async () => {
    actions = hot('-a|', { a: {type: 'Load'}} });
    console.log('testing');
});
});

现在从我的理解乳清运行规范它应该调用我的效果,但没有任何反应,测试只是运行完成。我在这里做错了什么?

我正在使用Jamine。

0 个答案:

没有答案