所以,我一直在尝试对 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');
关于unit-testing - Qunit 测试位于包含多个 Controller 的文件中的 ember Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24042155/