我正在尝试使用茉莉花大理石测试NGRX效果,但是我从effects.myEffect $获得的响应似乎嵌套了运算符。我期望的是观察到返回一个平坦的动作。任何帮助或意见将不胜感激。
it('Test Effect', async(inject([ServicesStub],
async (servicesStub: ServicesStub) => {
const payloadRequest = new RequestActionPayload();
const actionRequest = new RequestAction(payloadRequest);
const payloadResponse = new ResponseActionPayload();
const actionResponse = new ResponseActionPayload(payloadResponse);
const source = hot('a|', { a: actionRequest});
const effects = new NewEffectService(new Actions(source), ...);
const expected = cold('-a', { a: actionResponse });
expect(effects.myEffect$).toBeObservable(expected);}
)));
我的效果如下:
@Effect()
myEffect$ = this.actions$
.pipe(
ofType(actions.REQUEST_ACTION),
map((action: actions.RequestAction) => action.payload),
switchMap(payload => ... do some work),
map(([a, b]) => new actions.ResponseAction(new actions.ResponseActionPayload(...)))
);
我的package.json看起来像:
"jasmine-marbles": "^0.5.0"
"rxjs": "^6.5.1",
"@ngrx/effects": "^7.4.0",
"@ngrx/router-store": "^7.4.0",
"@ngrx/store": "^7.4.0",
"@ngrx/store-devtools": "^7.4.0",
嵌套的观察者/来源:
我从失败的测试中得到的错误是,我可能错误地认为这意味着可观察的值为空?
Expected $[0].frame = 0 to equal 10.
Expected $[0].notification.kind = 'E' to equal 'N'.
Expected $[0].notification.value = undefined to equal new actions.ResponseAction(new actions.ResponseActionPayload(...)).
Expected $[0].notification.error = TypeError: Cannot read property 'put' of null to equal undefined.
Expected $[0].notification.hasValue = false to equal true.