在没有Ember.run的情况下在测试模式下使用async / await

时间:2016-10-31 07:24:44

标签: ember.js

我试图在Ember 2.9项目中使用async / await函数。我有这个简单的代码:

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');
  }
});

我在开发模式下工作但是当我运行测试时,我收到了这条消息:

  

您已启用测试模式,该模式禁用了运行循环的自动运行。您需要在运行

中包装具有异步副作用的任何代码

我明白了,我可以使用Ember.run但是使用async / await变得完全无用。

有解决方案吗?

更新1

我尝试Ember.testing = false并且它有效,但我不确定它是否安全。我想我以后会遇到问题。你怎么想?

更新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);
    });
  });
});

0 个答案:

没有答案