【问题标题】:Ember-auth QUnit tests fail every second runEmber-auth QUnit 测试每第二次运行都会失败
【发布时间】:2014-01-22 23:21:22
【问题描述】:

我最近设法获得了我的ember-auth tests to pass,但它还不完美,因为测试每两次都失败(或者如果有多个测试正在运行,那么关于身份验证的每一次测试都会失败) .

我创建了一个small sample app 来演示失败。

您应该能够按照以下步骤重现故障:

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 格式”。下次刷新时它会再次起作用。

【问题讨论】:

标签: json ember.js qunit ember-testing


【解决方案1】:

我在使用本地存储保存会话时遇到了这个问题。这是因为 ember-testing 默认不清除本地存储。至少有三种方法可以解决这个问题:

  1. 通过 Ember Auth 使用临时存储
  2. 将本地存储删除添加到您的 setup/tearDown 函数中
  3. 将 Ember Auth logout 添加到 tearDown 功能

第一个解决方案似乎是最简单和最好的解决方案,因为可以将存储设置为仅用于 Ember Auth。 ember-auth 文档explains 存储选项:

饼干

App.Auth = Em.Auth.extend 
   session: 'dummy'

Dummy(用于单元测试)

App.Auth = Em.Auth.extend 
   session: 'cookie'

如果Ember.testing === true,您可能希望在初始化时将您的设置为 Dummy

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2012-10-13
    • 2017-05-28
    • 1970-01-01
    相关资源
    最近更新 更多