I created an Ember service that polls an API every second using getJSON. The code works fine in the browser but when I try to run tests on I am getting all sorts of errors including You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in a run
and Test timed out
. Is my Ajax call interacting with ember improperly? I can't seem to get the tests to run right.
schedulePollEvent(event, interval) {
var eventInterval = interval || this.get('eventInterval');
return Ember.run.later(() => {
event.apply(this);
this.set('timer', this.schedulePollEvent(event));
}, eventInterval);
},
startPolling(interval) {
this.set('timer', this.schedulePollEvent(this.get('onPollEvent'), interval));
},
stopPolling() {
Ember.run.cancel(this.get('timer'));
},
onPollEvent() {
Ember.$.getJSON('url', 'GET')
.then((data) => {
Ember.run(() => {
// Do something
});
}, (err) => {
console.log("Error hitting 'url': " + err);
}
);
}
Aucun commentaire:
Enregistrer un commentaire