【问题标题】:Qunit testing an Ember.js app with ember-simple-auth authentication?Qunit 使用 ember-simple-auth 身份验证测试 Ember.js 应用程序?
【发布时间】:2014-04-17 16:48:33
【问题描述】:

所以,我正在为使用 ember-simple-auth gem 进行登录身份验证的 Ember 应用程序编写 Qunit 测试(以 teaspoon 作为测试运行器),我的测试如下(咖啡脚本):

#=  require qunit_spec_helper

test "Employee signs in", ->
  expect(1)
  visit("/login").then(->
    fillIn "input.email", "employee1@example.com"
  ).then(->
    fillIn "input.user_password", "password1"
  ).then(->
    click "button.btn-primary"
  ).andThen ->
   equal(find('h2').length,1, "Welcome to the App")

这里是测试助手:

QUnit.testStart ->

  Ember.run ->
    App.reset()

  Ember.testing = true
    App.setupForTesting()
    App.injectTestHelpers()

QUnit.testDone ->
  Ember.testing = false

QUnit.done ->
  Ember.run ->
    App.reset()

当我运行测试时(密切关注控制台),我收到以下错误:

POST http://localhost:3000/teaspoon/qunit/oauth/token 404 (Not Found)

我似乎无法登录,无论如何.. 我的想法用完了,非常感谢任何帮助/建议:)

【问题讨论】:

    标签: javascript testing ember.js qunit teaspoon


    【解决方案1】:

    Ember.SimpleAuth 在单击按钮时向服务器发出请求以对会话进行身份验证-尽管您的服务器没有处理路由(或者服务器根本没有运行?)我会存根用于测试的令牌端点,找到一个示例,例如这里:https://github.com/digitalplaywright/eak-simple-auth/blob/master/tests/acceptance/login-test.js

    【讨论】:

    • 感谢您的回复,不使用sinon可以吗?
    • 当然还有其他请求存根库。或者您手动存根请求(我不推荐)。
    • 我为此苦苦挣扎。谢谢@marcoow。你真的很支持ember-simple-auth;继续努力!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多