【发布时间】:2019-11-20 17:19:09
【问题描述】:
我知道有一个类似的问题here
但我正在按照建议的答案进行操作,但我仍然收到此错误
基本上我有这样的功能
checkForInvitation() {
this._join.joinInformationSource.pipe(filter(x => x !== null)).subscribe(result => {
this.joinInformation = result;
this.setFields(result.userInfo);
});
}
基本上它获取信息,然后调用另一个方法来预填充一些表单字段。
现在我正在尝试测试这种方法,所以我创建了一个像这样的间谍......
// ...
const joinServiceSpy = jasmine.createSpyObj('JoinService', ['joinInformationSource']);
// ...
providers: [
{ provide: JoinService, useValue: joinServiceSpy }
]
// ...
joinService = TestBed.get(JoinService);
it('should prepopulate fields if there is join information', () => {
let joinInfoSpy = joinService.joinInformationSource.and.returnValue(
of(
// ... object
)
)
});
现在当我运行 ng test 时,我反复收到此错误
this._join.joinInformationSource.pipe is not a function
这是我的加入服务
joinInformationSource = new BehaviorSubject<JoinInformation>(null);
setJoinInformation(joinInformation: JoinInformation) {
this.joinInformationSource.next(joinInformation);
}
我在这里做错了什么??
【问题讨论】:
-
你能复制这个吗?
-
什么时候调用 checkForInvitation()?在构造函数/onInit 内部还是仅在模板交互上?
标签: angular