如何在Angular 2单元测试中测试拖放

时间:2017-02-02 11:57:59

标签: angular ionic-framework

我正在开发一款具有火种卡功能的Ionic 2应用。我想测试我的卡throwout事件,当卡被拖动超过限制时发生。我正在使用https://www.nist.gov/pml/time-and-frequency-division/popular-links/daylight-saving-time-dst库。

  

home.html的

<div swing-stack #myswing1 [stackConfig]="stackConfig"  id="card-stack">
  <button ion-button icon-only *ngIf="hunts.length == 0" (click)="loadHunts()"><ion-icon name="refresh-circle"></ion-icon></button>
  <ion-card swing-card #mycards1 *ngFor="let hunt of hunts"  [navPush]="showHuntPage" [navParams]="{hunt: hunt}" >
    <ion-card-header>
      {{hunt.title}}
    </ion-card-header>
    <ion-card-content>
      <div><img width="150" height="250" [src]="imageSource(hunt.picture_url)"></div>
      <div>
        {{hunt.clue}}
      </div>
      <div>
        {{hunt.distance_from_user }} away
      </div>
    </ion-card-content>
  </ion-card>
</div>
</ion-content>

通过拖动,每个ion-cardthrowable

我这样订阅throwing中的home.ts个活动。

    this.throwRightSub =  this.swingStack.throwoutright.subscribe( (event: ThrowEvent) => {
      let hunt = this.hunts.shift();
      this.reviewHunt("accepted",hunt);
      this.events.publish("hunt-accepted",hunt);
    });
    this.throwLeftSub = this.swingStack.throwoutleft.subscribe( (event: ThrowEvent) => {
      let hunt = this.hunts.shift();
      this.reviewHunt("rejected",hunt);
    });
  }

我看到点击事件被嘲笑

let el = fixture.debugElement.query(By.css('ion-card'));
el.triggerEventHandler('click', null);

无论如何在单元测试中触发drag事件?任何帮助,将不胜感激。

0 个答案:

没有答案