首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问成员-cli单元测试中的所需元素

如何访问成员-cli单元测试中的所需元素
EN

Stack Overflow用户
提问于 2015-06-19 06:15:06
回答 1查看 327关注 0票数 2

在路由测试中,我需要访问一个服务,检索一个模型。我已经通过需求引用了服务,但是在测试中我看不到访问服务的方法。

代码语言:javascript
复制
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)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-19 07:00:26

找到了解决办法。关键是在使用需要时,可以通过容器从测试中访问资源:

代码语言:javascript
复制
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');
 ...
})
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30931129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档