【问题标题】:Ember.js Acceptance Testing not waiting for asynchronous data operationsEmber.js 验收测试不等待异步数据操作
【发布时间】:2015-10-29 23:11:55
【问题描述】:

使用 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 数据适配器时也不会发生这些错误。

是什么导致了这些错误以及如何避免它们?

编辑:虽然症状有点不同(没有抛出错误),但听起来this problem 可能与我看到的错误有相同的根本原因。

【问题讨论】:

    标签: ember.js ember-data emberfire


    【解决方案1】:

    tl;博士

    为了解决这个问题,我一直在使用 custom test waiter. 您可以使用 ember install ember-cli-test-model-waiter 安装它(适用于 Ember v2.0+)

    更长的答案:

    这些问题的根本原因是 ember 测试系统不知道如何处理 Firebase 的异步性。对于大多数适配器,这不是问题,因为测试系统 instruments AJAX callsensures they have completed before proceeding,但这不适用于 Firebase 的 websockets 通信。

    因此,虽然这些错误在手动交互时不会发生,但我相信如果点击速度足够快,它们在技术上会发生。

    这些问题是known to occur with ember-pouch,并且可能也会出现在其他非 AJAX 适配器(例如本地存储适配器(12)或任何其他基于 websockets 的适配器上。它可能会出现在夹具适配器上,但这可能会立即返回结果,因此不会触发此问题)。其他异步进程也会发生这种情况,例如 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 postthis gist 提供了另一种更灵活的解决方案方法,但需要更多的手动记账。

    【讨论】:

      猜你喜欢
      • 2017-09-18
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      相关资源
      最近更新 更多