jeudi 2 mai 2019

getting error while setting a global variable during recurssion in ember.js

so i have implemented a timer in my ember code, which works fine, but while running test it fails i get this error saying

Uncaught Error: Assertion Failed: calling set on destroyed object: <front@component:qwtery/my-comp::ember629>.timer = 9

note that this happens only when i run the tests

and here is my code

didReceiveAttrs(){
    this._super(...arguments);
    this.set('timerStop', false);
    this.set('anotherTimer', 0);
    this.set('timer', null);
    var timeLimit = this.get('question.time_limit');
    if(timeLimit > 0)
    {
      this.set('timerEnabled', true);
      this.timerFunc(timeLimit,0);
    }
  },

timerFunc: function(count, val) {
    if (count >= 0 && !this.get('timerStop')) {
      this.set('timer', count);
      this.set('anothertimer', val);

      var a = setTimeout(() => {
        return this.timerFunc(count-1, val+1);
      }, 1000)
    }
    else {
      code to show message that timer has stopped
    }
  }

So if this is not the right way to implement a timer, why do i get the message "calling set on destroyed object:" only while running the test and not while i try it out manually




Aucun commentaire:

Enregistrer un commentaire