Unit test is failing for ngrx effect.
Effect method code:
addNewLedgerAccountRequest$ = createEffect(() =>
this.actions$.pipe(
ofType(AddNewLedgerAccountActions.AddNewLedgerAccountActionTypes.ADD_NEW_LEDGER_ACCOUNT_REQUEST),
withLatestFrom(this.addNewLedgerAccountStore$.select(AddNewLedgerAccountSelectors.ledgerAccountFormSelector)),
switchMap(([, addNewLedgerAccountForm]: [Action, LedgerAccountFormDef]) => {
return this.addNewLedgerAccountService.addNewLedgerAccount$(addNewLedgerAccountForm).pipe(
map((ledgerAccount: LedgerAccountDef) => new AddNewLedgerAccountActions.AddNewLedgerAccountSuccess({ ledgerAccount })),
catchError(() => of(new AddNewLedgerAccountActions.AddNewLedgerAccountFailure()))
);
})
)
);
Effect test method code:
describe(`AddNewLedgerRequest$`, () => {
it(`should dispatch AddNewLedgerAccountRequest action if service succeeds`, () => {
const action = new fromActions.AddNewLedgerAccountRequest();
actions$ = hot('-a', { a: action });
const outcome = new fromActions.AddNewLedgerAccountSuccess({ ledgerAccount: mockedLedgerAccount });
const expected$ = cold('--b', { b: outcome });
const result$ = cold( '-b', { b: mockedLedgerAccount } );
addNewLedgerAccountSpy.mockReturnValue( result$ );
expect( effects.addNewLedgerAccountRequest$ ).toBeObservable( expected$ );
expect( addNewLedgerAccountSpy ).toHaveBeenCalledWith( mockedLedgerAccountForm );
} );
} );
Result:
Expected: --b,
Received: --?,
Expected:
[{"frame":20,"notification":{"kind":"N","value":{"payload":{"ledgerAccount":{"id":"1234","name":"TestLedger","number":"3344","type":"12","taxRate":"12","taxRatePercent":"12"}},"type":"[point - CONFIGURATION WIZARD] Add new ledger account - Success"},"hasValue":true}}]
Received:
[{"frame":20,"notification":{"kind":"N","value":{"payload":{"ledgerAccount":{"id":"1234","name":"TestLedger","number":"3344","type":"12","taxRate":"12","taxRatePercent":"12"}},"type":"[point - CONFIGURATION WIZARD] Add new ledger account - Success"}}}],
86 | const result$ = cold( '-b', { b: mockedLedgerAccount } );
87 | addNewLedgerAccountSpy.mockReturnValue( result$ );
> 88 | expect( effects.addNewLedgerAccountRequest$ ).toBeObservable( expected$ );
| ^
89 | expect( addNewLedgerAccountSpy ).toHaveBeenCalledWith( mockedLedgerAccountForm );
90 | } );
The only difference is Expected has ,"hasValue":true and Received is missing it. Please let me know how to solve it. Thank you,