I'm trying to use async/await functions in an Ember 2.9 project.I have this simple code :
import Route from 'ember-route';
export default Route.extend({
async model(params) {
const activity = await this.store.findRecord('activity', params.activity_id);
this.set('activity', activity);
return activity.get('courses');
}
});
I works on dev mode but when I run a test, I have this message :
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
I understood than I can use Ember.run
but using async/await become completly useless.
Is there a solution ?
Update 1
I tried to do Ember.testing = false
and it works but I'm not sure it's safe. I think I will have problems later. What you think?
Update 2
import destroyApp from '../helpers/destroy-app';
import {describe, it, beforeEach, afterEach} from 'mocha';
import {expect} from 'chai';
import startApp from '../helpers/start-app';
import {authenticateSession} from '../helpers/ember-simple-auth';
import page from 'tiny/tests/pages/courses';
describe('Acceptance: Courses', ()=> {
let application;
beforeEach(function () {
$.Velocity.mock = true;
application = startApp();
authenticateSession(application, {data: {attributes: {fullaccess: true, 'access-token': 123}}});
});
afterEach(function () {
destroyApp(application);
});
it('can view list of courses', function () {
const activity = server.create('activity');
server.create('course', {activity: activity, name: 'Test course'});
visit('/kohorde-admin/activities/1/courses');
andThen(()=> {
expect(page.coursesCount()).to.eq(1);
});
});
});