ngrx エフェクトの単体テストを書いています。私はそれをすべて試しましたが、このエラーを乗り越えることができないようです:
Expected $[0].notification.kind = 'E' to equal 'N'.
Expected $[0].notification.value = undefined to equal Object({ vendors: [ Object({ id: 1234, code: 'tst', name: 'test', freePlay: true, freeSpin: false, disabled: true, active: false }) ], type: '[CasinoVendors API] Get Vendors Success' }).
Expected $[0].notification.error = TypeError: Cannot read property 'sort' of undefined to equal undefined.
Expected $[0].notification.hasValue = false to equal true.
私がテストしようとしている効果は次のとおりです。
getVendors$ = createEffect(() => this.actions$.pipe(
ofType(CasinoVendorsActions.getVendors),
concatMap(() => this.casinoVendorsSvc.getVendors()
.pipe(
map((data: any) => {
let vendors: VendorModel[] = data
return CasinoVendorsActions.getVendorsSuccess({vendors: vendors});
})
))
)
);
単体テスト:
describe('getVendors', () => {
it('should return a stream with getVendorsSuccess action', () => {
const vendors: VendorModel[] = [{
id: 1234,
code: 'tst',
name: 'test',
freePlay: true,
freeSpin: false,
disabled: true,
active: false,
}];
const action = CasinoVendorsActions.getVendors();
const outcome = CasinoVendorsActions.getVendorsSuccess({vendors: vendors});
actions$ = hot('-a', { a: action });
const response = cold('-a|', { a: vendors });
casinoVendorsSvc.getVendors.and.returnValue(response);
const expected = cold('--b', { b: outcome });
expect(effects.getVendors$).toBeObservable(expected);
});
});
効果は正しいデータで満たされたアクション「getVendorsSuccess」を返すため、問題はこの部分にあると思われます。
const expected = cold('--b', { b: outcome });
expect(effects.getVendors$).toBeObservable(expected);
どんな提案でも大歓迎です