ultimatecourses / ngrx-store-effects-app

Project seed app for our NGRX application using Angular, NGRX Store, Effects, Router Store.
https://ultimateangular.com/ngrx-store-effects
532 stars 1.17k forks source link

testing effect Error #20

Open GuillaumeUnice opened 6 years ago

GuillaumeUnice commented 6 years ago

Hi there,

I correctly understand the testing Effects. Nevertheless, I encounter an error when I try to test a Http Failed mocked.

Is that possible to add a fail test case? I encounter this kind of error: Error: Expected $[1].frame = 0 to equal 10. the test case:

it('should return GetFailedAction action, with the errror, on fail', async () => {

    const { effects, TodoService, actions$ } = setup()

    const action = new GetAction()
    const errorMsg = {message: 'Error: an error 40X occured'}
    const expectedResult = new GetFailedAction(errorMsg.message)

    // mock this function which we can test later on, due to the promise issue
    spyOn(effects, 'getTodo').and.returnValue(Observable.throw(errorMsg))

    actions$.stream = hot('a|', { a: action });
    const expected = cold('b|', { b: expectedResult })

    expect(effects.getTodo$).toBeObservable(expected)
    // expect(effects.getTodo).toHaveBeenCalled()

})