【问题标题】:RxJs - Jasmine marbles forkJoin operator testRxJs - Jasmine marbles forkJoin 算子测试
【发布时间】:2019-10-13 03:47:27
【问题描述】:

这里是forkJoin operator jasmine marble test:

it('test1', () => {

 const a = cold('---a|', { a: 1 });
 const b = cold('---b|', { b: 2 });

 const observable = forkJoin(
   a,
   b
 );

 const expected = cold('---21');
 expect(observable).toBeObservable(expected);
});

测试产生以下错误:

Expected $[0].frame = 40 to equal 30.
Expected $[0].notification.value = [ 1, 2 ] to equal '2'.
Expected $[1].frame = 40 to equal 50.
Expected $[1].notification.kind = 'C' to equal 'N'.
Expected $[1].notification.value = undefined to equal '1'.
Expected $[1].notification.hasValue = false to equal true.

谁能告诉我我做错了什么?

【问题讨论】:

标签: angular jasmine rxjs jasmine-marbles


【解决方案1】:

首先---21 将等待三帧,然后发出'2',然后发出'1。分叉连接不是merge,它会发出一次,它会发出[1, 2]

字母数字弹珠在发射时会前进一帧。所以ab 都将在第 4 帧完成。然后 forkJoin 将解析 emit。然后 forkJoin 将立即完成(也在第 4 帧)。

所以你得到的错误:

Expected $[0].frame = 40 to equal 30. fork-join 发出的第一项是在时间 4(因为 a 和 b 在时间 4 完成)而不是在时间 3。

Expected $[0].notification.value = [ 1, 2 ] to equal '2'. 发出的值是[1, 2] 而不是'2',如上所述。

Expected $[1].frame = 40 to equal 50.
Expected $[1].notification.kind = 'C' to equal 'N'.
Expected $[1].notification.value = undefined to equal '1'.
Expected $[1].notification.hasValue = false to equal true.

您期望在时间 5 收到 '1'。它在时间 4 收到 complete

所以你可能想要...

const expected = cold('----(a|)', { a: [1, 2] });
expect(observable).toBeObservable(expected);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 2018-01-04
    • 2019-04-13
    • 2018-05-15
    • 2019-01-26
    • 2019-02-06
    相关资源
    最近更新 更多