0

我无法moduleFor使用 ember-cli 0.1.5 版在新版本中工作。

当使用文档的示例代码(并且没有对应用程序进行moduleFor其他更改)时,运行后出现以下错误ember test

TypeError: Attempting to register an unknown factory: `route:index`
    at Object.Container.register (http://localhost:4200/assets/vendor.js:14473:17)
    at isolatedContainer (http://localhost:4200/assets/test-support.js:24:19)
    at Object._callbacks.setup (http://localhost:4200/assets/test-support.js:150:23)
    at Object.Test.setup (http://localhost:4200/assets/test-support.js:1063:31)
    at http://localhost:4200/assets/test-support.js:1168:10
    at process (http://localhost:4200/assets/test-support.js:887:24)
    at http://localhost:4200/assets/test-support.js:476:5

由于除了在 /tests/unit/index-test.js 中添加示例示例之外,我没有对应用程序进行任何更改moduleFor,这似乎是一个 ember-cli 错误?作为参考,下面是moduleFor示例的代码:

// my-app/tests/unit/index-test.js
import { test, moduleFor } from 'ember-qunit';

moduleFor('route:index', "Unit - IndexRoute", {
  setup: function () {},
  teardown: function () {}
});

test("it exists", function(){
  ok(this.subject());
});
4

1 回答 1

3

路由似乎是在路由到时自动生成的。但是当你像你正在做的那样运行一个单元测试时,除非你明确声明一个,否则moduleFor()不会有一个。IndexRoute如果你想要一个IndexRoute你可以测试的,你需要手动定义它:

import Ember from 'ember'

IndexRoute = Ember.Route.extend();

export default IndexRoute

如果你真的只想依赖自动生成的,没有理由对它进行单元测试,因为没有额外的功能需要测试。

我想如果你打开,LOG_ACTIVE_GENERATION那么你可以看到什么时候生成的。

如果您确实想测试自动生成的,请在验收测试的上下文中进行,此时您可以使用路由器路由到那里。

我的猜测是它在这里生成。

于 2015-01-27T02:38:06.437 回答