在路由测试中,我需要访问一个服务,检索一个模型。我已经通过需求引用了服务,但是在测试中我看不到访问服务的方法。
import {
moduleFor,
test
} from 'ember-qunit';
moduleFor('route:application', {
needs: ['route:application','controller:application','service:dialog']
});
test('can open and remove a dialog dialog', function(assert) {
var route = this.subject();
route.setProperties({
controller: { // don't like this part as well ..
dialogs:null
}
});
// need to access the service here to get a model
// something like :
//var service = this.get('service:dialog');
var modalModel = service.getModal('business/contract-edit');
...
});如何访问测试中的服务?
(顺便说一句:我用的是EMBERV2.0.0)
发布于 2015-06-19 07:00:26
找到了解决办法。关键是在使用需要时,可以通过容器从测试中访问资源:
moduleFor('route:application', {
// Specify the other units that are required for this test.
needs: ['route:application','controller:application','service:dialog']
});
test('can open and remove a dialog dialog', function(assert) {
var route = this.subject();
var controller = this.container.lookup('controller:application');
var service = this.container.lookup('service:dialog');
...
})https://stackoverflow.com/questions/30931129
复制相似问题