在测试中使用访问时出现错误:
TypeError:对象#没有方法'getHandler'
module("visit", {
setup: function() {
Ember.run(App, App.advanceReadiness);
},
teardown: function() {
App.reset();
}
});
test("visit works", function () {
expect(2);
// this gets executed
equal(1, 1);
return visit("/").then(function() {
// this doesn't
equal(1, 1);
});
});
产生的错误跟踪为:
Died on test #2 at eval (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:10:1)
at eval (native)
at eval (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066), <anonymous>:2:14066)
at Function.p.extend.globalEval (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066), <anonymous>:2:14077)
at p.ajaxSetup.converters.text script (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066), <anonymous>:2:83767)
at cC (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066), <anonymous>:2:5874)
at y (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066), <anonymous>:2:79888)
at d (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066), <anonymous>:2:85578): Object #<Object> has no method 'getHandler'
Source:
TypeError: Object #<Object> has no method 'getHandler'
at generateHandlerInfos (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:25824:31)
at performTransition (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:25758:30)
at createURLTransition (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:25501:18)
at doTransition (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:26067:20)
at Object.Router.handleURL (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:25213:20)
at Ember.Router.Ember.Object.extend._doTransition (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:26491:53)
at Ember.Router.Ember.Object.extend.handleURL (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:26331:21)
at Ember.Application.Ember.Namespace.extend.handleURL (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:30240:16)
at Object.Backburner.run (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:4862:30)
at Object.Ember.run (eval at <anonymous> (eval at <anonymous> (http://127.0.0.1:3000/javascripts/libs/jquery/jquery-1.8.0.min.js:2:14066)), <anonymous>:5200:30)
我已经确保按照this answer的建议在运行测试之前加载了Ember。 QUnit也可以正常运行,因为灯具的基本测试正在运行。
我现在已经在这个问题上花费了数小时,而且我不知道为什么会这样。
编辑(跟随丹尼尔的评论)
路线非常简单,看起来像这样:
App.IndexRoute = Ember.Route.extend({
redirect: function(){
this.transitionTo('about');
}
});
App.Router.map(function(){
this.route('about');
});
最佳答案
你应该去读http://emberjs.com/guides/testing/integration/
使用最新的Ember,您不需要运行App.advanceReadiness
,只需运行App.reset
中的teardown
,并且在定义任何测试套件之前,您需要调用:
App.rootElement = '#qunit-fixtures';
App.setupForTesting();
App.injectTestHelpers();
一切都应该正常工作。
Lemme知道遵循此方法是否不起作用,如果可以,请给我一个jsbin; ;-)
编辑
我也不确定这会改变什么,但是在他们的例子中,他们使用的是
andThen
而不是then
:visit('/');
andThen(function(){ ... });