簡體   English   中英

如何在茉莉花測試用例中模擬事件停止在角度6中的傳播

[英]How to mock event stop propagation in angular 6 for jasmine test case

我如何模擬茉莉花測試用例的事件停止傳播(角度6)。

我正在嘗試-

 it('should call the onItemRightClick method', () => {

    event = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']);
    expect(event.stopPropagation).toHaveBeenCalled();
    component.onItemRightClick(params.event, params.ci);
    // expect(component.onItemRightClick).toHaveBeenCalled();

  });

組件代碼-

  onItemRightClick(event: MouseEvent, ci: CiWithKPIS) {
    console.debug('Open context panel for CI', ci.name);
    event.stopPropagation();
    if (!this.isSelected(ci)) {
      this._selectedItems = [ci];
      this.onSelectedCisChanged.emit(this._selectedItems);
    }
}

但這是行不通的。 它給出錯誤TypeError: event.stopPropagation is not a function請指導。

您已經在事件對象上創建了間諜。 但在component.onItemRightClick方法中傳遞不同的對象。 使用以下行來解決問題。

component.onItemRightClick(event,params.ci);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM