has no method ' getHandler'"when calling visit-6ren"> has no method ' getHandler'"when calling visit-我在测试中使用 visit 时遇到错误: TypeError: 对象 # 没有方法 'getHandler' module("visit", { setup: function() { E-6ren">
gpt4 book ai didi

javascript - Ember.js 和 QUnit : "TypeError: Object # has no method ' getHandler'"when calling visit
转载 作者:行者123 更新时间:2023-12-03 13:07:29 25 4
gpt4 key购买 nike

我在测试中使用 visit 时遇到错误:

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 也正常工作,因为对固定装置的基本测试正在运行。

我现在已经在这个问题上花了几个小时,但我不知道为什么会这样。

编辑(根据 Daniel 的评论)路线非常简单,看起来像这样:

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,只需运行 teardown 中的 App.reset,以及之前定义任何测试套件,您需要调用:

App.rootElement = '#qunit-fixtures';
App.setupForTesting();
App.injectTestHelpers();

一切都应该工作正常。

让我知道如果按照这个行不通,如果是的话,给我一个我可以处理的 jsbin ;-)

编辑

我也不确定这会改变什么,但在他们的例子中他们使用 andThen 而不是 then:

visit('/');
andThen(function(){ ... });

关于javascript - Ember.js 和 QUnit : "TypeError: Object #<Object> has no method ' getHandler'"when calling visit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18429030/

25 4 0