Ember测试:您已打开测试模式,禁用了运行环的自动运行 [英] Ember testing: You have turned on testing mode, which disabled the run-loop's autorun
问题描述
我正在尝试编写一个简单的Ember集成测试,并继续使用 Ember.run
来获得令人沮丧的运行循环错误。我有一个梦are,试图让这个工作,如果有人可以帮助我,我会很感激。具体来说,我可以看到测试登录,并开始加载下一页(应该),但一旦测试完成,我会收到该错误。这是关于第二次测试,第一次通过(因为没有什么是异步我相信)。
I am trying to write a simple Ember integration test and continue to get the frustrating run loop error despite using Ember.run
. I've had a nightmare of a time trying to get this to work, if anyone could help me I'd be so grateful. Specifically, I can see the test sign in and begin loading the next page (as it should), but as soon as the test finishes I get that error. This is regarding the second test, the first passes (as nothing is async I believe).
import Ember from 'ember';
import startApp from 'jobs-tuftsdaily/tests/helpers/start-app';
import exists from 'jobs-tuftsdaily/tests/helpers/start-app';
var App;
module('Integration - Landing Page', {
setup: function() {
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
test('Should load content', function() {
visit('/').then(function() {
ok(exists("*"), "Found HTML!");
ok(exists('label:eq(4)'), "Slug label on page");
});
});
test('Should sign in test user', function() {
Ember.run(function() {
visit('/').andThen(function() {
return fillIn("input[name=email]", "test@test.com");
}).andThen(function() {
return fillIn("input[type=password]", "password");
}).andThen(function() {
return click("button");
}).andThen(function() {
ok(1, "stupid test passed");
});
});
});
推荐答案
我意识到我迟到了,无论如何:
I realize I am late to the party, but here goes anyway:
在您的组件或应用程序代码(即不在测试代码中)的某个地方,您可能会听到Ember之外的一些事件(例如DOM事件,通过jQuery或类似的东西),但尝试在该处理程序运行期间与它进行交互。这些处理函数必须包含在$ code> Ember.run.bind()中,否则它们在测试期间不会有一个循环。在处理程序期间,Ember.run.bind()还将为您设置此
。
Somewhere in your component or application code (that is, NOT in the test code), you probably listen to some event outside of Ember (e.g. a DOM event, through jQuery, or something like that), but try to interact with it during that handler's run. These handler functions must be wrapped in Ember.run.bind()
, or they won't have a runloop during a test. Ember.run.bind()
will also set this
for you during the handler.
如果您不在 Ember.run.bind()
中包装事件回调,代码可能会在应用程序的正常运行期间,仍然运行没有麻烦,因为自动运行功能会发现运行环境要求(例如,如果您使用 Ember.run.schedule()
处理程序)在代码中与Ember进行交互,并为它们启动一个运行循环,但是在测试中被关闭。
If you don't wrap your event callbacks in Ember.run.bind()
, the code will probably still run without hassle during a normal run of the application because the autorun feature will find runloop-demanding (for example, if you schedule something using Ember.run.schedule()
during the handler) interactions with Ember in the code and start a runloop for them, but it's turned off in tests.
这篇关于Ember测试:您已打开测试模式,禁用了运行环的自动运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!