首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Ember-Cli中使用单元测试类方法?

如何在Ember-Cli中使用单元测试类方法?
EN

Stack Overflow用户
提问于 2014-12-23 23:55:45
回答 1查看 142关注 0票数 1

在我的应用程序中,我想在我的GooglePlaceRetriever服务上测试一个类方法。我知道,在使用Ember进行测试时,我可以使用this.subject()获取服务的实例,但我不确定如何访问实际的GooglePlaceRetriever对象本身来测试类方法。

代码语言:javascript
复制
import {
  moduleFor,
  test
} from 'ember-qunit';

moduleFor('service:google-place-retriever', 'GooglePlaceRetrieverService', {
  // Specify the other units that are required for this test.
  // needs: ['service:foo']
});

// Replace this with your real tests.
test('it exists', function() {
  var service = this.subject();
  ok(service);
});

test('fetches place details from Google and converts it to a location', function()
  //Cannot figure out how to access the Class as opposed to the instance.
  var location = ???.findByPlaceId('ChIJaeKPQD_zz4kRy4c8TvnwGIg');

  ok(location.get('name'), "My Name");
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-24 06:43:31

您可以访问类方法来进行这样的测试:

代码语言:javascript
复制
var location = this.subject.constructor.findByPlaceId('whatever');

但是为什么要使用类方法呢?服务不应该实例化吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27629728

复制
相关文章

相似问题

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