Ember-auth QUnit测试每秒钟运行失败 [英] Ember-auth QUnit tests fail every second run
问题描述
我最近设法让我的 ember-auth测试通过,但它还不完美,因为测试每次第二次失败(或者如果有几个测试运行,每隔一秒的验证失败)。
I have recently managed to get my ember-auth tests to pass, but it's not yet perfect, as the tests fail every second time (or if there are several tests running, every second test about authentication fails).
我已经创建了一个小样本应用程序来演示失败。
I have created a small sample app to demonstrate the failure.
您应该可以通过以下步骤重现故障:
You should be able to reproduce the failure by following these steps:
1. git clone https://github.com/pedrokost/ember_auth_testing_example.git
2. cd ember_auth_testing_example
3. ruby -run -e httpd . -p5000 # (or any HTTP server like: python -m SimpleHTTPServer)
4. Open http://localhost:5000?test in the browser
如果测试通过,刷新页面,看到它失败,无效的JSON格式。下一次刷新时,它再次工作。
If the tests passes, refresh the page and see it fail with "Invalid JSON format". Next time you refresh it works again.
推荐答案
使用本地存储保存会话时,我遇到了这个确切的问题。这是因为默认情况下,ember测试不会清除本地存储。至少有三种方法来解决这个问题:
I had this exact problem when using local storage to save my session. This is because the ember-testing does not clear local storage by default. There are at least three ways to solve this:
- 使用Ember Auth的短暂存储
- 添加将本地存储删除到您的设置/ tearDown功能
- 将Ember Auth注销添加到tearDown功能
第一个解决方案似乎是最简单和最好的解决方案,因为可以将存储设置为Ember Auth。 ember-auth文档解释存储选项:
The first solution seems to be the simplest and best solution since it's possible to set the storage to just for Ember Auth. The ember-auth documentation explains storage options:
Cookie
App.Auth = Em.Auth.extend
session: 'dummy'
虚拟(单元测试)
App.Auth = Em.Auth.extend
session: 'cookie'
如果 Ember.testing === true
这篇关于Ember-auth QUnit测试每秒钟运行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!