Angular 角形8,茉莉花<;spyOn>;:找不到要监视bind()的对象

Angular 角形8,茉莉花<;spyOn>;:找不到要监视bind()的对象,angular,jasmine,bind,Angular,Jasmine,Bind,对于我的Angular组件,我有一个基类,为了保持当前上下文,我有以下绑定代码。如果我console.log,我可以看到调用了updateReference,但jasmine无法检测是否调用了它 如果我使用以下命令,我会在标题处出错 spyOn(fixture.componentInstance.updatePreference.prototype, 'bind').and.callThrough(); 我的设置有什么遗漏吗 Profile-component.ts扩展了Profile-bas

对于我的Angular组件,我有一个基类,为了保持当前上下文,我有以下绑定代码。如果我
console.log
,我可以看到调用了
updateReference
,但jasmine无法检测是否调用了它

如果我使用以下命令,我会在标题处出错

spyOn(fixture.componentInstance.updatePreference.prototype, 'bind').and.callThrough();
我的设置有什么遗漏吗

Profile-component.ts扩展了Profile-base.ts

Profile-base.ts(基类)

剖面-组件规范ts


经过一些尝试和失败,我注意到它的工作,如果我重新安排顺序如下

let fixture = TestBed.createComponent(ProfileComponent);

// hold the spy reference
let spyReference = spyOn(fixture.componentInstance, updatePreference).and.callThrough();

// then trigger OnInit to do binding  
fixture.detectChanges();

// then write your expection against spy reference
expect(spyReference ).toHaveBeenCalledWith('123', '456');
public openRemovePanel(itemGuid: string, callbackFunction: (id: string, data: string) => void) { 
….
callbackFunction(id, data);
}
fit('this should work', () => {
let fixture = TestBed.createComponent(ProfileComponent);
fixture.detectChanges();

// tried both of the following
spyOn(fixture.componentInstance.updatePreference.prototype, 'bind').and.callThrough();
spyOn(fixture.componentInstance, updatePreference).and.callThrough();

…...
// make a call to openRemovePanel, and that triggers updatePreference
……

// this does not work
expect(fixture.componentInstance.updatePreference).toHaveBeenCalled();
})
let fixture = TestBed.createComponent(ProfileComponent);

// hold the spy reference
let spyReference = spyOn(fixture.componentInstance, updatePreference).and.callThrough();

// then trigger OnInit to do binding  
fixture.detectChanges();

// then write your expection against spy reference
expect(spyReference ).toHaveBeenCalledWith('123', '456');