Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timing / Framing issue with Jasmine-marbles using hot and cold

I've got a quick demo people can download here: https://stackblitz.com/edit/angular-vczzqp Just hit export in the top right, in your favourite terminal and run install and ng test with your favourite browser.

Basically the issue, to me, seems to be that the internal timings of Jasmine are not matching for the objects.

Below is test as well as the exact error I get. See the example under app/Test for the full test class

it('should return a GET_GENERIC_FAILED when the services throws', () => {
    const action = new genericActions.GetAllGenericAction();

    genericsService.getAllGenerics.and.returnValue(Observable.throw({}));

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

    expect(effects.getAllGenerics).toBeObservable(expected);
});

And the error

Expected
    [Object({
        frame: 0,
        notification: Notification({
            kind: 'N',
            value: GetGenericFailedAction({
                type: '[GENERIC] Get Generic Failed'
            }),
            error: undefined,
            hasValue: true
        })
    }), Object({
        frame: 0,
        notification: Notification({
            kind: 'C',
            value: undefined,
            error: undefined,
            hasValue: false
        })
    })]
    to equal
    [Object({
        frame: 0,
        notification: Notification({
            kind: 'N',
            value: GetGenericFailedAction({
                type: '[GENERIC] Get Generic Failed'
            }),
            error: undefined,
            hasValue: true
        })
    })].

Any guidance would be appreciated.

like image 934
Questioning Avatar asked Feb 15 '18 20:02

Questioning


1 Answers

It looks like this is an issue over how errors are thrown.

The fix was to add | to mark the observable as completed as well as to wrap the expected observable in () to group the operation together.

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

Documentation on the syntax is here however the docs for internal maintainers seems a little easier to digest.

like image 165
Questioning Avatar answered Nov 19 '22 22:11

Questioning