【发布时间】:2016-01-20 14:02:27
【问题描述】:
我无法在我的 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 中未定义,有人有单元测试工作吗?我可以转换为集成测试,但如果可能,我更愿意将其保留为单元级别。
【问题讨论】:
-
在您的路线中尝试过
session: inject.service(),? -
查看了源代码,这就是 mixin 中发生的事情,无论如何都尝试过,但没有任何影响。好主意。
标签: unit-testing ember.js ember-simple-auth