茉莉花单元测试无法激活组件功能

时间:2019-06-19 04:56:19

标签: angular unit-testing

无法在showCreateUserPanel中激活我的功能 期望console.log和updateDefaultValue已被调用

使用By.css获取指令并激活(create)=“ showCreateUserPanel()”函数

<wizard-quick-search-page *ngIf="initSearchPanel" [createUserAttributes]="createUserAttributes"
  [existingUserAttributes]="existingUserAttributes" (edit)="showEditUserPanel($event)"
  (create)="showCreateUserPanel($event)">
</wizard-quick-search-page>
  public showCreateUserPanel(event: any): void {
    console.log(event);
    this.pageType = 'create';

    if (this.initSearchPanel)
      this.searchPanel.close();

    if (this.initCreateEditPanel)
      this.createEditPanel.open();
    else
      this.initCreateEditPanel = true;

    this.displayValues = event.displayValues;
    this.formPage = event.formPage;

    this.updateDefaultValue(this.formPage, this.createUserAttributes);
  }
  describe('wizard quick search page', () => {
    beforeEach(() => {
      component.initSearchPanel = true;
      fixture.detectChanges();
      mockQuickSearchDirective = fixture.debugElement.query(By.css('wizard-quick-search-page'));
    });

    it('should open a create new user panel', () => {
      spyOn(component, 'showCreateUserPanel');
      mockQuickSearchDirective.triggerEventHandler('create', null);
      fixture.detectChanges();
      expect(component.showCreateUserPanel).toHaveBeenCalled();
    });

    it('should open a edit existing user panel', () => {
      spyOn(component, 'showEditUserPanel');
      mockQuickSearchDirective.triggerEventHandler('edit', null);
      fixture.detectChanges();
      expect(component.showEditUserPanel).toHaveBeenCalled();
    });

期望console.log已被调用

0 个答案:

没有答案