简体   繁体   English

ReferenceError:未定义 spyOnProperty

[英]ReferenceError: spyOnProperty is not defined

it('should update treatment instruction data in UI', async(() => {
     const spy = spyOnProperty(appService.treatmentInstruction, 'next', 
     'get').and.returnValue(treatmentInst);

    component.updateTemplateInUI();
    fixture.whenStable().then(() => {
        expect(component.structuresInfo.length).toBe(2);
        expect(component.oarStructureLength).toBe(4);
        expect(component.notesArray.length).toBe(2);
    });
}));

ReferenceError: spyOnProperty is not defined error is coming on running test case. ReferenceError: spyOnProperty is not defined 运行测试用例时出现错误。

I want to spyOn treatmentInstruction BehaviorSubjectthat is present in my service as mentioned below :我想监视我的服务中存在的治疗指令 BehaviorSubject,如下所述:

treatmentInstruction = new BehaviorSubject(this.myGlobalVar);
currentTreatmentInstruction = this.treatmentInstruction.asObservable();

spyOnProperty was added on jasmine 2.6.0, be sure that you fulfill that requisite. 在jasmine 2.6.0上添加了spyOnProperty ,请确保您满足该要求。

Since jasmine is a dependency of karma-jasmine update that instead. 由于jasminekarma-jasmine的依赖,因此更新karma-jasmine Looks like on old version of this library jasmine was added as a peer dependency so it would be up to you to install the correct version of jasmine . 看起来在该库的旧版本上, jasmine被添加为对等依赖项,因此您可以自行决定安装正确版本的jasmine

按照“ @ types / jasmine”:“〜2.8.3”,“ jasmine-core”:“〜2.8.0”,

I had this issue, updating jasmine version didn't help.我有这个问题,更新茉莉花版本没有帮助。 The problem came for jshint, in your test directory you must modify your .jshuntrc file : in "globals": { add => "spyOnProperty" : false问题出在 jshint,在您的测试目录中,您必须修改您的 .jshuntrc 文件:在“globals”中:{ add =>“spyOnProperty”:false

Worked for me为我工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM