unit-testing - Qunit 测试位于包含多个 Controller 的文件中的 ember Controller ?

标签 unit-testing testing ember.js qunit ember-qunit

所以,我一直在尝试对 Ember Controller 进行 qunit 测试,问题是,该 Controller 位于包含多个 Controller 的 coffeeScript 文件中。

现在,ember testing guide says ,为了测试 Controller ,我应该像这样使用“moduleFor”助手:

moduleFor(fullName [, description [, callbacks]])

在我的例子中,全名是:“CustomersIndexController”,但是因为它包含在“customers_controller.coffee”中,它本身包含多个 Controller ,所以测试它变得有问题。

在网上无休止的挖掘之后,我 found out (如果我错了,请纠正我)解析器只关心文件名,而不关心 'export default myModel' 提供的名称

为了更清楚,这是我的“customers_controller.coffee”:

`export { CustomersIndexController, CustomersItemController }`

CustomersIndexController = Ember.ArrayController.extend
#Code goes here ......

CustomerItemController = Ember.ObjectController.extend
#Code goes here .....

这是 customers-controller-test.coffee 文件:

`import { test, moduleFor } from 'ember-qunit';`
 moduleFor("controller:customers-index-controller", 'C Controller') 

 test "it's an App.Controller", -> ok(@subject())

我已经尝试了我的大脑可以产生的所有想法......没有任何运气(将 Controller 名称从驼峰式更改为破折号,更改为绝对路径,甚至尝试导入 customers_controller.coffee),但我不断得到:

Setup failed on it's a App.Controller: Attempting to register an unknown factory: `controller:customers-index-controller`

非常感谢任何帮助/建议/链接。

最佳答案

您应该能够使用小驼峰命名来定义它。

moduleFor('controller:postsIndex', 'Posts Index Controller');

http://jsbin.com/ruhalota/1/edit

关于unit-testing - Qunit 测试位于包含多个 Controller 的文件中的 ember Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24042155/

相关文章:

java - Junit 测试空指针异常

perl - Devel::Cover 测试覆盖选项

ember.js - 动画 View 转换。如何推迟删除或插入元素?

javascript - 观察 @each 时了解哪个项目触发事件

javascript - hasMany 关系中的 Ember 数据可变数组

Python 单元测试/测试夹具测试模块是否已加载

python - 是否可以使用 Django 的固定装置更改现有数据?

unit-testing - Fluent NHibernate PersistenceSpecification 组件和引用测试

javascript - Protractor :如何检查表格/网格是否已填充?

javascript - 如果路径名以 . 开头,并且包含 .正则表达式