Angular 角度笑话:间谍属性(类似于茉莉花) 请引导我创建SpyOnProperty(如Jasmine)以开玩笑

Angular 角度笑话:间谍属性(类似于茉莉花) 请引导我创建SpyOnProperty(如Jasmine)以开玩笑,angular,jestjs,Angular,Jestjs,我在Jest中监视子类上的属性,但是没有像jasmine in Jest中预定义的spyOnProperty()这样的东西 如何监视子组件的属性 成分 规格 错误 Uncaught(承诺中):错误:无法对原语值进行间谍;未定义的给定错误:无法对基元值进行间谍;未定义的给定值 fixture = TestBed.createComponent(ParentComponent); component = fixture.componentInstance;

我在Jest中监视子类上的属性,但是没有像jasmine in Jest中预定义的
spyOnProperty()
这样的东西

如何监视子组件的属性

成分 规格 错误
Uncaught(承诺中):错误:无法对原语值进行间谍;未定义的给定错误:无法对基元值进行间谍;未定义的给定值

           fixture = TestBed.createComponent(ParentComponent);
           component = fixture.componentInstance;
       >   jest.spyOn(component.btn, 'searchText', 'get').mockReturnValue('bar');
                   ^
           fixture.detectChanges();
       }));

你能分享你的错误输出吗?有什么是无效的?@Tugayİlik,我更新了问题中的错误,请看。你得到这个错误是因为你试图监视一个不存在的属性。
component.smartTable
是否存在?如果存在,是否存在
component.smartTable.searchText
并且它是一个getter?@Tugayİlik为混淆道歉,我已经编辑了这个问题。是的,
btn
存在。能否添加
ButtonComponent
getters代码
describe('ParentComponent', () => {
    //.............

    fixture = TestBed.createComponent(ParentComponent);
    component = fixture.componentInstance;
    spyOnProperty(component.btn, 'state').and.returnValue('active); // jasmine
    jest.spyOn(component.btn, 'text', 'get').mockReturnValue('bar');// jest -> INVALID
    fixture.detectChanges();

    //----------
});
           fixture = TestBed.createComponent(ParentComponent);
           component = fixture.componentInstance;
       >   jest.spyOn(component.btn, 'searchText', 'get').mockReturnValue('bar');
                   ^
           fixture.detectChanges();
       }));