javascript - ReferenceError: spyOnProperty is not defined - Stack Overflow

it('should update treatment instruction data in UI', async(() => {const spy = spyOnPropert

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

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

ReferenceError: spyOnProperty is not defined error is ing on running test case.

I want to spyOn treatmentInstruction BehaviorSubjectthat is present in my service as mentioned below :

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

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

ReferenceError: spyOnProperty is not defined error is ing on running test case.

I want to spyOn treatmentInstruction BehaviorSubjectthat is present in my service as mentioned below :

treatmentInstruction = new BehaviorSubject(this.myGlobalVar);
currentTreatmentInstruction = this.treatmentInstruction.asObservable();
Share Improve this question asked Jan 11, 2019 at 6:49 Nilesh GuptaNilesh Gupta 812 silver badges9 bronze badges 10
  • that should be spyOn – quirimmo Commented Jan 11, 2019 at 6:54
  • spyOn is for installing spy on function. I want to spyOn on service property of type Observable. – Nilesh Gupta Commented Jan 11, 2019 at 6:58
  • What is the version of jasmine you are using? – Rakesh Makluri Commented Jan 11, 2019 at 7:01
  • "karma-jasmine": "~1.1.1", – Nilesh Gupta Commented Jan 11, 2019 at 7:02
  • Upgrade to latest version, it should work. – Rakesh Makluri Commented Jan 11, 2019 at 7:08
 |  Show 5 more ments

3 Answers 3

Reset to default 3

spyOnProperty was added on jasmine 2.6.0, be sure that you fulfill that requisite.

Since jasmine is a dependency of karma-jasmine update that instead. 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.

Upgrade following "@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

Worked for me

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744853884a4597289.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信