【发布时间】:2014-07-25 09:09:58
【问题描述】:
所以,我一直在尝试对 Ember 控制器进行 qunit 测试,但问题是,控制器位于一个包含多个控制器的咖啡脚本文件中。
现在,ember testing guide says,为了测试控制器,我应该像这样使用“moduleFor”助手:
moduleFor(fullName [, description [, callbacks]])
在我的例子中,全名是:“CustomersIndexController”,但是因为它包含在“customers_controller.coffee”中,它本身包含多个控制器,所以测试它变得有问题。
在无尽的在线挖掘之后,我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())
我已经尝试了我的大脑可以产生的所有想法...没有任何运气(将控制器名称从 camelCase 更改为 dasherized,更改为绝对路径,甚至尝试导入 customers_controller.coffee),但我不断得到:
Setup failed on it's a App.Controller: Attempting to register an unknown factory: `controller:customers-index-controller`
非常感谢任何帮助/建议/链接。
【问题讨论】:
标签: unit-testing testing ember.js qunit ember-qunit