【发布时间】:2014-04-16 23:45:07
【问题描述】:
我正在尝试为我的 Ember 应用执行集成/验收测试。我正在专门测试用户身份验证(例如 - 提交登录表单)和需要经过身份验证的用户的受保护页面/状态。
关于我的应用的一般说明:
- 使用Ember App Kit
- 使用ember-simple-auth 进行身份验证
- 我有 api-stubs 用于我的 ember-simple-auth 表单,可以使用 Devise 授权器进行访问。在浏览器中运行应用时,这些都可以正常工作。
我有三个问题:
1。设计身份验证器和临时存储
在 ember-simple-auth API 中,它指的是使用临时存储进行测试。我已经这样做了,much like this。但是,会话似乎仍存储在本地存储中。如果我没有在每个测试设置/拆卸中执行localStorage.clear(),测试会失败,因为在第一个测试之后运行每个测试时我仍然保持登录状态。
当我为我的应用使用 Devise 身份验证器时,我是否能够防止在每次测试之间将会话存储在本地存储中?
2。多重验收测试
如果我尝试在超过 1 个test() 中使用log in a user,我的测试将进入无限循环。第一个测试会通过,但是当第二个测试提交登录表单时,整个测试套件会停止并重新启动。
集成测试 #1
App = null
module('Acceptance - Page #1',
setup: ->
App = startApp()
teardown: ->
Ember.run(App, 'destroy')
)
test('page #1 behind authentication', ->
expect(1)
visit('/page-1')
fillIn('input#identification', 'foo@bar.com')
fillIn('input#password', 'password')
click('button[type="submit"]')
andThen(->
equal(true, true) # This test works fine
)
)
集成测试 #2
App = null
module('Acceptance - Page #2',
setup: ->
App = startApp()
teardown: ->
Ember.run(App, 'destroy')
)
test('page #2 behind authentication', ->
expect(1)
visit('/page-2')
fillIn('input#identification', 'foo@bar.com')
fillIn('input#password', 'password')
click('button[type="submit"]')
andThen(->
equal(true, true) # Never runs, tests start over, infinite loop begins
)
)
3。 EAK api-stubs & Testem
EAK's api-stubs 似乎无法用于 Testem,因此通过命令行/Testem 运行时这些验收测试中的“登录”过程失败。
我尝试了setting up sinon.js,但上述问题使我无法确定它是否真正正常工作。使用 ember-simple-auth 成功存根登录用户的最佳方法是什么?是否可以将 EAK 的 api-stub 用于 Testem?
【问题讨论】:
标签: authentication ember.js ember-app-kit ember-qunit ember-simple-auth