mercredi 18 mars 2020

Ember-unit test for setInterval function --Ember

i am a noob, who started working on a feature in Ember JS and am currently in process of writing unit tests for the following but not sure how.. The basic functionality here is certain properties are set based on the inactivity time and this check runs every two seconds. How do i write unit tests using sinon or whichever to fake the warning times(4 and 5min)

    firstWarning: 240000;//4min
     secondWarning: 300000;//5min

  start() {
    this.set(
      "timer",
      setInterval(() => {

        //inactive time is the difference between session start time which is
        //calculated by performance.now and lastRefresh(time when user has last refreshed the page)
        let inactivityValue = performance.now() - this.get("lastRefresh");
        let firstWarning = this.get("firstWarnTime");
        let secondWarning = this.get("secondWarnTime");

        if (inactivityValue < firstWarning) {
          this.set("firstPopup", false);
          this.set("secondPopup", false);
        } else if (inactivityValue >= firstWarning && inactivityValue < secondWarning) {
          this.set("firstPopup", true);
          this.set("secondPopup", false);
        } else if (inactivityValue >= secondWarning) {
          this.set("firstPopup", false);
          this.set("secondPopup", true);
        }
      }, 2000)
    );
  }



Aucun commentaire:

Enregistrer un commentaire