Unit testing 如何在ember simple auth中为单元测试注入会话?

Unit testing 如何在ember simple auth中为单元测试注入会话?,unit-testing,ember.js,ember-simple-auth,Unit Testing,Ember.js,Ember Simple Auth,我无法在我的ember应用程序中设置应用程序路由的单元测试 非常简单的路线: import Ember from 'ember'; import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; export default Ember.Route.extend(ApplicationRouteMixin, {}); 非常简单的测试: import { moduleFor, t

我无法在我的ember应用程序中设置应用程序路由的单元测试

非常简单的路线:

import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin, {});
非常简单的测试:

import {
  moduleFor,
  test
} from 'ember-qunit';


import { authenticateSession } from '../../helpers/ember-simple-auth';

moduleFor('route:application', {
    beforeEach: function(){
        this.subject().set('session', authenticateSession);
    },
});

test('it exists', function(assert) {
  var route = this.subject();
  assert.ok(route);
});
我尝试过几种方法,但都有错误:

Promise rejected before it exists: 'undefined' is not an object (evaluating '_this.get('session').on')

这似乎表明会话在mixin中未定义,有人让单元测试工作吗?我可以转换为集成测试,但如果可能的话,我更愿意将其作为一个单元级别。

如果其他人遇到这种情况,它只是一个“需要:['service:session']”,如以下不同答案所示:


您是否在路线中尝试了
会话:inject.service(),
?查看源代码,这就是mixin中发生的事情,尽管尝试了,但没有任何影响。好主意。