Ember.js 不等待异步数据操作的验收测试
Ember.js Acceptance Testing not waiting for asynchronous data operations
使用 Emberfire (Firebase) 适配器时,我收到各种错误,表明测试没有等待数据操作完成。
例如:Error: Assertion Failed: You can only unload a record which is not inFlight.
当我尝试创建、检查然后删除一条记录时
另外:
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
在我的应用程序中手动导航时不会出现这些错误,使用标准 ember 数据适配器时也不会出现这些错误。
是什么导致了这些错误,我该如何避免它们?
编辑:虽然症状有点不同(没有抛出错误),但听起来 可能与我看到的错误具有相同的根本原因。
tl;博士
为了解决这个问题,我一直在使用 custom test waiter. 您可以使用 ember install ember-cli-test-model-waiter
安装它(适用于 Ember v2.0+)
更长的答案:
这些问题的根本原因是ember测试系统不知道如何处理Firebase的异步性。对于大多数适配器,这不是问题,因为测试系统 instruments AJAX calls and ensures they have completed before proceeding,但这不适用于 Firebase 的 websockets 通信。
因此,尽管手动交互时不会发生这些错误,但我相信如果点击速度足够快,它们在技术上是可以发生的。
这些问题是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)
custom test waiter I mentioned in the tl;dr 的工作原理是在继续测试之前等待所有模型解析,因此应该适用于所有这些非 AJAX 适配器。
有关 ember 的测试如何在幕后处理异步性的更多背景信息,Cory Forsyth has a helpful blog post, and this gist 提供了另一种更灵活的解决方案,但这需要更多的手动簿记。
使用 Emberfire (Firebase) 适配器时,我收到各种错误,表明测试没有等待数据操作完成。
例如:Error: Assertion Failed: You can only unload a record which is not inFlight.
当我尝试创建、检查然后删除一条记录时
另外:
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
在我的应用程序中手动导航时不会出现这些错误,使用标准 ember 数据适配器时也不会出现这些错误。
是什么导致了这些错误,我该如何避免它们?
编辑:虽然症状有点不同(没有抛出错误),但听起来
tl;博士
为了解决这个问题,我一直在使用 custom test waiter. 您可以使用 ember install ember-cli-test-model-waiter
安装它(适用于 Ember v2.0+)
更长的答案:
这些问题的根本原因是ember测试系统不知道如何处理Firebase的异步性。对于大多数适配器,这不是问题,因为测试系统 instruments AJAX calls and ensures they have completed before proceeding,但这不适用于 Firebase 的 websockets 通信。
因此,尽管手动交互时不会发生这些错误,但我相信如果点击速度足够快,它们在技术上是可以发生的。
这些问题是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)
custom test waiter I mentioned in the tl;dr 的工作原理是在继续测试之前等待所有模型解析,因此应该适用于所有这些非 AJAX 适配器。
有关 ember 的测试如何在幕后处理异步性的更多背景信息,Cory Forsyth has a helpful blog post, and this gist 提供了另一种更灵活的解决方案,但这需要更多的手动簿记。