Ember.js验收测试不等待异步数据操作 [英] Ember.js Acceptance Testing not waiting for asynchronous data operations

查看:185
本文介绍了Ember.js验收测试不等待异步数据操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Emberfire(Firebase)适配器时,我收到各种错误,表示测试没有等待数据操作完成。



eg:错误:断言失败:当我尝试创建,检查,然后删除记录时,您只能卸载不在Flash中的记录。

另外:



FIREBASE警告:用户回调抛出异常。错误:在import.default._emberTestingAdaptersAdapter.default.extend.asyncStart在Object.extend.stop(http:// localhost:4200 / assets / test-support.js:3000:10)下调用stop()



手动浏览我的应用程序时,也不会在使用标准的ember数据适配器时,不会发生这些错误。



什么是导致这些错误,如何避免这些错误?



编辑:虽然症状有点不同(没有错误抛出)这听起来像此问题可能具有相同的根本原因

解决方案

tl; dr



要解决此问题,我一直在使用定制测试服务员。您可以使用 ember install ember-cli-test-model安装它-waiter (适用于Ember v2.0 +)



更长的回答:



这些问题的根本原因是,ember测试系统不知道如何处理Firebase的异步。对于大多数适配器,这不是问题,因为测试系统乐器AJAX调用确保在继续之前已经完成,但这并不适用于Firebase的websockets通信。



所以尽管这些错误手动交互时不要发生,我相信如果可以点击足够快,技术上可能会发生。



这些问题是发生的.com / nolanlawson / ember-pouch / issues / 27rel =nofollow,并且很可能与其他非AJAX适配器(例如localstorage适配器( 1 2 )或任何其他基于Web套接字的适配器。它可能与夹具适配器发生,但这可能会立即返回结果,因此不会触发此问题)。它也发生在其他异步进程,如液体动画动画以类似的方式修复



我在tl; dr 中提到的定制测试服务员通过等待对于所有型号在进行测试之前要解决,所以应该使用所有这些非AJAX适配器。



有关Ember的测试如何处理异步的更多背景引擎盖, Cory Forsyth有一个有用的博客文章,以及这个要点提供了另一种更灵活的解决方案,但这需要更多手动簿记。


When using the Emberfire (Firebase) adapter, I'm getting various errors that indicate the tests are not waiting for data operations to complete.

eg: Error: Assertion Failed: You can only unload a record which is not inFlight. when I try to create, check, and then delete a record

Also:

FIREBASE WARNING: Exception was thrown by user callback. Error: Called stop() outside of a test context at Object.extend.stop (http://localhost:4200/assets/test-support.js:3000:10) at exports.default._emberTestingAdaptersAdapter.default.extend.asyncStart

These errors do not occur while manually navigating through my app, nor when using the standard ember data adapter.

What is causing these errors and how do I avoid them?

Edit: although the symptoms are a bit different (no error thrown), it sounds like this problem may have the same root cause as the errors I've been seeing.

解决方案

tl;dr

To work around the issue, I've been using a custom test waiter. You can install it with ember install ember-cli-test-model-waiter (works with Ember v2.0+)

Longer answer:

The root cause of these problems is that the ember testing system doesn't know how to handle Firebase's asynchronicity. With most adapters, this isn't a problem, because the testing system instruments AJAX calls and ensures they have completed before proceeding, but this doesn't work with Firebase's websockets communication.

So although these errors don't occur when interacting manually, I believe they technically could if it were possible to click fast enough.

These problems are known to occur with ember-pouch and will likely also occur with other non-AJAX adapters (eg. localstorage adapters (1, 2), or any other websockets-based adapter. It may occur with the fixture adapter, but that may return results immediately and so not trigger this problem). It also happens with other asynchronous processes, like liquid-fire animations (fixed in a similar way)

The custom test waiter I mentioned in the tl;dr works by waiting for all models to resolve before proceeding with the test, and so should work with all of these non-AJAX adapters.

For more background on how ember's testing deals with asynchronicity under the hood, Cory Forsyth has a helpful blog post, and this gist gives another more flexible solution approach but that requires more manual book-keeping.

这篇关于Ember.js验收测试不等待异步数据操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆