2015-01-10 37 views
0

我不能讓moduleFor在使用ember-cli 0.1.5版的新版本中工作。ember-cli:moduleFor失敗,顯示「試圖註冊一個未知的工廠」錯誤

當使用documentation's example codemoduleFor(並沒有其他變化的應用程序),我收到以下錯誤運行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()); 
}); 
+0

這條路線是否存在? –

+0

是的,我相信這條路線存在。索引路由是自動創建的路由之一(來自http://emberjs.com/guides/routing/defining-our-routes/#toc_initial-routes)。 – jake

+0

是的,但我想知道當試圖實例化一個自動生成的路由進行測試時它是否有所不同。如果您在'app/routes/index.js'添加路線,錯誤會消失嗎?如果你沒有路線,你想要測試什麼? –

回答

3

好像路由是自動生成的,當它被路由到。但是當像你這樣使用moduleFor()進行單元測試時,除非明確聲明一個,否則不會有IndexRoute。如果你想要一個IndexRoute你可以測試一下,你需要手動定義它:

import Ember from 'ember' 

IndexRoute = Ember.Route.extend(); 

export default IndexRoute 

如果你真的只是想依靠自動生成的一個,沒有理由進行單元測試,因爲沒有額外的功能來測試。

我想如果你打開LOG_ACTIVE_GENERATION那麼你可以看到什麼時候產生了。

如果您確實想測試自動生成的測試,請在驗收測試的上下文中進行測試,當您可以使用路由器在此處進行路由時。我想這是生成here

相關問題