我们已经有一个应用程序正在运行,只是为了 CI 的目的向它添加测试用例。
我们有一个小代码来尝试登录过程并检查在可能的登录状态(如成功、失败、无效帐户帐户被锁定等)之后发生的情况。
所以我尝试了以下代码。
visit('/login')
.fillIn('#identification', "testuser")
.fillIn('#password', "testpass")
.click('input[type="submit"]')
andThen(function(){
ok(!exists('button:contains(sign in)'), '3. Login button is not displayed when authenticated');
ok(exists('.dropDownMenuOptions li:contains(Logout)'), '4. Logout button is displayed when authenticated');
});
它在控制台中给出以下错误。
ember.debug.js:5162 Uncaught Error: Assertion Failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in a run
此错误发生在执行点击后。当点击对服务器进行 AJAX 调用时,根据其响应进行路由转换。
对于成功登录的情况,我想检查我的路由是否从 /login
更改为 /
由于此错误我无法执行此操作。
请提出建议。
谢谢
最佳答案
在处理表单提交的 Controller /组件中,您必须做一组(示例)
save: function() {
this.get('model').set('name', 'foo');
}
如果这项工作是在某个 ajax 事件之后在运行循环(异步)中完成的,请确保像这样用 ember run 包装它
save: function() {
Ember.run(function() {
this.get('model').set('name', 'foo');
});
}
关于javascript - 测试 : You will need to wrap any code with asynchronous side-effects in a run 时出现 Ember 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31467547/