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

1

7

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.

Mcmorris answered 15/2, 2018 at 20:11 Comment(0)
M
21

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.

Mcmorris answered 16/2, 2018 at 15:18 Comment(1)
I was messing around with my marble diagrams in tests and this (b|) part actually worked in my case. Still confused about these diagrams though.Blindage

© 2022 - 2024 — McMap. All rights reserved.