简体   繁体   中英

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.

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

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

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 .

按照“ @ 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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