【发布时间】:2020-01-17 11:29:11
【问题描述】:
我正在尝试为我的组件中的一个功能编写单元测试,在本示例中,它是“设置”。 'setup' 调用另一个函数,'additionalSetup',它在执行管道(take(1))时订阅存储,并获取第一个发射:
private setup() {
// ...declares/assigns a few variables in the component
this.additionalSetup() ;
}
private additionalSetup() {
this.store.pipe(take(1)).subscribe(/*logic here, but you get the idea*/);
}
我的单元测试似乎因错误而失败:
TypeError: 无法读取未定义的属性“管道”
在“设置”单元测试中,我尝试模拟“附加设置”:
component.additionalSetup = jest.fn();
这似乎不起作用。我对开玩笑还很陌生,我还在学习。我将采取什么方法来解决此错误?
【问题讨论】:
-
this.store是undefined,无论出于何种原因,当您调用该代码时。
标签: typescript unit-testing jestjs observable ngrx