【发布时间】:2013-03-21 12:51:43
【问题描述】:
我正在使用 Jasmine 对 EmberJS 项目进行单元测试,但在使用 Ember 的需求 API 时遇到问题。
当我尝试运行 jasmine 测试时,如果相关控制器具有“需求”以及调用
的 init 函数,它们将无法创建控制器实例this._super()
我收到此控制台错误
"不能调用方法'has' of null"
当我尝试调试时,将我带入了 Ember 的内部,但我无能为力。
任何人都知道我做错了什么
Application.SearchPendingController = Ember.ObjectController.extend({
needs: ['searchResults', 'search'],
shouldDisable: false,
searchResultsController: null,
init: function () {
this._super();
this.set('searchResultsController', this.controllerFor('searchResults'));
this.get('controllers.search.content').reload();
this.get('controllers.searchResults').set('content', this.get('controllers.search.content.results'));
},
transitionToResults: function () {
console.log('yay');
}.observes('this.searchResultsController.content')
});
当我尝试创建此控制器时,jasmine 测试会引发错误
var searchPendingController = Application.SearchPendingController.create();
有人对此有任何想法吗?
【问题讨论】:
标签: javascript unit-testing ember.js jasmine