我从观察点返回一个物体。它的一个属性是函数。
在分配了甚至是空函数并发出对象之后,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中定义。有可能吗?
发布于 2019-09-09 15:39:29
事实证明,可以这样定义expected:
const expected = m.cold('(b|)', { b: {
label: 'A',
action: expect.any(Function)
} });结果将会匹配。
奇怪的是,我想我几天前试过了,然后它就不起作用了,但也许我做的不一样。
https://stackoverflow.com/questions/57826181
复制相似问题