调用了未捕获的预期间谍错误

时间:2019-05-01 08:40:05

标签: javascript angular jasmine karma-jasmine

我正在为此编写单元测试。

    public showAdminAction(hraData: PhpGrid) {
        if (this.isInvalidMasterChildHealthPlanMapped(hraData.MasterChildHealthPlanId)) {
            this.showInvalidMasterChildHealthPlanPopUp(hraData);
        }
        else this.hraLockService.getHraLockDetail(hraData.HraId).then((res: any) => {
            if (res.LockedBy) {
                this.customDialogService.error(this.translateService.get("RecordLocked"), this.translateService.get("RecordLockedFromAdminAction").format(res.LockedBy));
            } else {
                this.customDialogService.createDialog(hraData, AdminActionComponent);
            }
        });
    }

   private isInvalidMasterChildHealthPlanMapped(masterChildHealthPlanId: number): boolean {
    if (this.siteService.getSiteHealthPlans() && masterChildHealthPlanId && !this.siteService.getSiteHealthPlans().find(x => x.Id == masterChildHealthPlanId)) {
        return true;
    }
    return false;
}

private showInvalidMasterChildHealthPlanPopUp(phpRowData: PhpGrid) {
    this.loggingService.log(this.translateService.get('IncorrectMasterChildHealthPlanMappedHraLog').replace('##hraId##', phpRowData.HraId.toString()).replace('##masterChildHealthPlanId##', phpRowData.MasterChildHealthPlanId.toString()).replace('##code##', MasterEventLookupTypeEnum.IncorrectMasterChildHealthPlanMappedHra.toString()), MasterEventTypeEnum.Error, MasterEventLookupTypeEnum.IncorrectMasterChildHealthPlanMappedHra, MasterLogLevelEnum.Error, MasterEventRecordTypeEnum.HRA, phpRowData.HraId);
    this.customDialogService.error(this.translateService.get("Error"), this.translateService.get("IncorrectMasterChildHealthPlanMappedHra").replace("##code##", MasterEventLookupTypeEnum.IncorrectMasterChildHealthPlanMappedHra.toString()));
}   

这些是我写的UT

describe('showAdminAction', () => {
    it('shows error dialog when InvalidMasterChildHealthPlanMapped', () => {
        let dataHelper: PhpGridMockDataHelper = new PhpGridMockDataHelper();
        let data = dataHelper.getPhpGridDataRawFormat();
        let res: any = { LockedBy: 'TestUser' };
        let siteHealthPlan: SiteHealthPlan[] = [{ Id: 2, Name: "OTHER STANDARD | MEDICARE", HraTypeFlag: 31, DefaultHraTypeId: 1, MasterPlanTypeId: 1, MasterPlanTypeName: null, VisitTypes: null, SortOrder: 3 }];

        spyOn(customDialogService, 'error');
        spyOn(hraLockService, 'getHraLockDetail').and.returnValue(Promise.resolve(res));
        spyOn(siteService, 'getSiteHealthPlans').and.returnValue(siteHealthPlan);

        pwqGridComponent.showAdminAction(data.Rows[2]);

        expect(customDialogService.error).toHaveBeenCalled();
    });
});

describe('showAdminAction', () => {
    it('shows error dialog when validMasterChildHealthPlanMapped but locked by user', () => {
        let dataHelper: PhpGridMockDataHelper = new PhpGridMockDataHelper();
        let data = dataHelper.getPhpGridDataRawFormat();
        let res: any = { LockedBy: 'TestUser' };
        let siteHealthPlan: SiteHealthPlan[] = [{ Id: 1, Name: "OTHER STANDARD | MEDICARE", HraTypeFlag: 31, DefaultHraTypeId: 1, MasterPlanTypeId: 1, MasterPlanTypeName: null, VisitTypes: null, SortOrder: 3 }];

        spyOn(customDialogService, 'error');
        spyOn(hraLockService, 'getHraLockDetail').and.returnValue(Promise.resolve(res));
        spyOn(siteService, 'getSiteHealthPlans').and.returnValue(siteHealthPlan);

        pwqGridComponent.showAdminAction(data.Rows[2]);

        expect(customDialogService.error).toHaveBeenCalled();
    });
});

describe('showAdminAction', () => {
    it('shows custom dialog when validMasterChildHealthPlanMapped and not locked by user', () => {
        let dataHelper: PhpGridMockDataHelper = new PhpGridMockDataHelper();
        let data = dataHelper.getPhpGridDataRawFormat();
        let res: any = { LockedBy: null };
        let siteHealthPlan: SiteHealthPlan[] = [{ Id: 1, Name: "OTHER STANDARD | MEDICARE", HraTypeFlag: 31, DefaultHraTypeId: 1, MasterPlanTypeId: 1, MasterPlanTypeName: null, VisitTypes: null, SortOrder: 3 }];

        spyOn(customDialogService, 'createDialog').and.returnValue(Observable.of(true));
        spyOn(hraLockService, 'getHraLockDetail').and.returnValue(Promise.resolve(res));
        spyOn(siteService, 'getSiteHealthPlans').and.returnValue(siteHealthPlan);

        pwqGridComponent.showAdminAction(data.Rows[2]);

        expect(customDialogService.createDialog).toHaveBeenCalled();
    });
});

但是我在最后两个UT上遇到以下错误:

FAILED PwqGrid组件showAdminAction在有效MasterChildHealthPlanMapped但被用户锁定时显示错误对话框

zone.js:199被调用的未预期的间谍错误。     在UserContext上。 (http://localhost:9876/base/config/spec-bundle.js:128900:47

FAILED PwqGrid组件showAdminAction在有效MasterChildHealthPlanMapped且未被用户锁定时显示自定义对话框

zone.js:199已被调用的预期的间谍createDialog。     在UserContext上。 (http://localhost:9876/base/config/spec-bundle.js:128913:54

0 个答案:

没有答案