第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法使用 ngif 讀取 null 的屬性“nativeElement”

無法使用 ngif 讀取 null 的屬性“nativeElement”

www說 2023-08-24 18:16:55
我正在做一些單元測試。所以我有這個功能:selectCluster(event: MouseEvent, feature: any) {    event.stopPropagation();     this.selectedCluster = {geometry: feature.geometry, properties: feature.properties};  }和模板: <mgl-popup *ngIf="selectedCluster" [feature]="selectedCluster">          </mgl-popup>我有這樣的測試:  fit('Should set selectedCluster when clicked', async(() => {        spyOn(component, 'selectCluster').and.callThrough();    fixture.detectChanges();    fixture.debugElement.query(By.css('.marker-cluster')).nativeElement.click();    tick();    fixture.whenStable().then(() => {      expect(component.selectCluster).toHaveBeenCalled();    });  }));但我仍然收到此錯誤:Cannot read property 'nativeElement' of null那么我必須改變什么?謝謝這也使用了以下函數(shù): <ng-template mglClusterPoint let-feature>        <div class="marker-cluster" (click)="selectCluster($event, feature)">          <fa-icon [icon]="faVideo" [styles]="{'stroke': 'black', 'color': 'black'}" size="lg" class="pr-2"></fa-icon>          <fa-icon [icon]="faWifi" [styles]="{'stroke': 'black', 'color': 'black'}" size="lg" class="pr-2"></fa-icon>        </div>      </ng-template>
查看完整描述

1 回答

?
一只斗牛犬

TA貢獻1784條經(jīng)驗 獲得超2個贊

.marker-cluster當(dāng)您嘗試單擊它時,它不在頁面上,我沒有看到您的完整 html,但我會假設(shè)它與*ngIf="selectedCluster"真實相關(guān)。


 fit('Should set selectedCluster when clicked', async(() => {    

    // spy on and calling through doesn't actually call the function

    // it makes it so we can determine if the function was called

    // and everytime the function was called, call the actual function

    // and not a null function

    spyOn(component, 'selectCluster').and.callThrough();

    // calling the function will should make selectedCluster true

    component.selectCluster({ stopPropagation: () => null } as MouseEvent, {}); // send your own inputs

    fixture.detectChanges();

    fixture.debugElement.query(By.css('.marker-cluster')).nativeElement.click();


    fixture.whenStable().then(() => {

      expect(component.selectCluster).toHaveBeenCalled();

    });

  }));


查看完整回答
反對 回復(fù) 2023-08-24
  • 1 回答
  • 0 關(guān)注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號