【问题标题】:RxJS marble testing objects with functionsRxJS 弹珠测试对象的功能
【发布时间】:2020-01-09 13:52:11
【问题描述】:

我从 Observable 返回一个对象。它的属性之一是函数。
在分配空函数并发出对象后,toBeObservable 期望由于非深度匹配而失败。

我正在使用rxjs-marbles/jest 进行测试。这是示例测试用例:

it('...', marbles(m => {
  const source = m.cold('(a|)');
  const expected = m.cold('(b|)', { b: {
    label: 'A',
    action: () => { }
  } });

  const destination = source.pipe(
    map(() => ({
      label: 'A',
      action: () => { }
    }))
  );
  m.expect(destination).toBeObservable(expected);
}));

结果如下:

expect(received).toEqual(expected) // deep equality

Expected: [{"frame": 0, "notification": {"error": undefined, "hasValue": true, "kind": "N", "value": {"action": [Function action], "label": "A"}}}, {"frame": 0, "notification": {"error": undefined, "hasValue": false, "kind": "C", "value": undefined}}]
Received: serializes to the same string

我唯一需要检查的是 action 是否在 object.有可能吗?

【问题讨论】:

    标签: javascript typescript jestjs rxjs-marbles


    【解决方案1】:

    原来可以这样定义expected

    const expected = m.cold('(b|)', { b: {
        label: 'A',
        action: expect.any(Function)
      } });
    

    结果会匹配。

    奇怪的事情,我想我几天前尝试过,然后它不起作用,但也许我做了一些不同的事情。

    【讨论】:

      猜你喜欢
      • 2019-12-15
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      相关资源
      最近更新 更多