单元测试需要检查模态窗口是否打开

时间:2018-11-13 15:05:17

标签: angular unit-testing observable angular6 angular-test

我想检查单元测试的角度是否为'

  

常量对话框

'模态窗口适用。我必须模拟从数据库获取数据。我尝试创建一个新的Subject()并调用它,但是每当我得到一个空对象时,我做错了什么。 我有这样的代码.ts:

  onOpenEvent(event: CalendarEvent) {
if (event.title !== CalendarTypeConverterUtils.PRIVATE && Terminart.getArt(event.meta) === Terminart.ZTV) {
  this.openTerminDetailModal(event.meta);
   }

    if (Terminart.getArt(event.meta) === Terminart.BANKSPRECHZEIT) {
  const anfangDatum = new Date(event.meta.anfang);
  this.newTermin(anfangDatum);
   }
   }

    private openTerminDetailModal(termin: Termin) {
const terminDetailDialog = this.modalService.open(TerminAnzeigeComponent, { centered: true });
terminDetailDialog.componentInstance.termin = termin;
 }

   openNeuTerminModel(termin: Termin) {
const terminErstellDialog = this.modalService.open(TerminFormularComponent, { size: 'lg', centered: true });

    if (termin.anfang && termin.ende) {
     terminErstellDialog.componentInstance.updateForm(termin);
   }

    terminErstellDialog.result.then((result) => {
     this.updateCalendarEvents();
     if (this.paramService.hatBereitsTerminErstellt) {


const Dialog =this.modalService.open(TerminBestaetigungComponent, { size: 'lg', centered: true });
    terminBestaetDialog.componentInstance.result = result;
      }
    });
  }

我的单元测试:

    it('should show popup if termin is create', () => {
      const myTrigger = new Subject();
       const modal = {
        componentInstance: {
        termin: {} as Termin,
         updateForm(newTermin: Termin) {
          this.termin = newTermin;
        }
       },
      result: myTrigger.toPromise()
    };
  myTrigger.next({
    id: 'test1',
    betreff: 'betreff von test1',
    herkunft: 'definitely not ztv',
    anfang: new Date(2017, 0, 1, 10, 42).getTime()
  });

     const testCalendarEvent: CalendarEvent<Termin> = {
    start: new Date(Number(myTrigger.asObservable.arguments.anfang)),
    title: 'definitely not private',
    meta: myTrigger.asObservable.arguments
  };

  component.onOpenEvent(testCalendarEvent);

  (component as any).paramService.hatBereitsTerminErstellt = true;

const TerminBestaetigungComponent= spyOn((component as any).modalService, 'open').and.returnValue(modal);

  expect(TerminBestaetigungComponent.calls.count()).toBe(1);
});

我收到一些奇怪的消息:TypeError:严格模式函数或调用它们的参数对象上可能无法访问“ caller”,“ callee”和“ arguments”属性

0 个答案:

没有答案