var model, controller;
// Set up the controller in a new container.
// On tear down, set the variables to null,
// we reset the app on setup.
module('User Edit Controller', {
setup: function(){
AisisPlanner.reset();
controller = AisisPlanner.__container__.lookup('controller:user_edit');
model = AisisPlanner.User.store.createRecord('user', {
name: 'john doe',
userName: 'john_doe',
email: '[email protected]',
bio: '',
pictureUrl: '',
role: 'Administrator'
});
controller.set('model', model)
},
teardown: function(){
controller = null;
model = null
}
});
test('capatalize_user_name', function(){
model.set('userName', 'John doe')
equal(controller.get('userName'), 'JOHN DOE', 'all caps');
});
以下測試很容易找出正在做什麼,從當前容器和模型設置控制器。然後在該模型中設置信息並在測試中使用它來傳播名稱。爲什麼這個灰燼測試失敗 - Ember JS,控制器
的問題是,我收到錯誤:
Setup failed on capatalize_user_name: 'undefined' is not an object (evaluating 'AisisPlanner.User.store.createRecord')
和
Died on test #2 global [email protected]://localhost:3000/assets/controllers/user_edit_controller_test.js?body=1:26:5: 'undefined' is not an object (evaluating 'model.set')
我從想法:this blog post on how to test controllers.我認爲它主要是過時,但我嘗試它沒有少。任何想法如何解決這一問題?
哈,絕對不是,只是一個口吃的錯字,而只打左手。 – Kingpin2k
現在會引發兩個新錯誤:capatalize_user_name上的安裝程序失敗:斷言失敗:您已打開測試模式,該模式禁用了運行循環的自動運行。您需要將任何帶有異步副作用的代碼封裝在Ember.run中 來源:\t http:// localhost:3000/assets/ember.js?body = 1:61 在測試#2上死亡全局代碼@ http:// localhost:3000/assets/controllers/user_edit_controller_test.js?body = 1:26:5:'undefined'不是一個對象(評估'model.set') – TheWebs
我把一個運行在回答中的例子,在測試中未定義模型? – Kingpin2k