使用冷热的茉莉花弹珠的时间/框架问题

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

我有一个快速演示,人们可以在这里下载:https://stackblitz.com/edit/angular-vczzqp只需在您最喜欢的终端中点击右上角的导出,然后 运行 installng test 使用您最喜欢的浏览器。

基本上,对我来说,问题似乎是 Jasmine 的内部时序与对象不匹配。

下面是测试以及我得到的确切错误。有关完整测试,请参阅 app/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);
});

错误

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
        })
    })].

如有任何指导,我们将不胜感激。

看起来这是关于如何抛出错误的问题。

解决方法是添加 | 以将可观察对象标记为已完成,并将预期的可观察对象包装在 () 中以将操作组合在一起。

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

内部维护者的语法文档 here however the docs 似乎更容易理解。