【发布时间】:2014-04-10 18:59:56
【问题描述】:
在我的 Ember App Kit 应用程序中测试 Ember Simple Auth 时,我想模拟服务器登录响应。但是,使用以下代码,当在访问函数上调用点击操作时,我会收到一个不透明的错误“意外结束输入”:
var App;
module('Acceptances - SignIn', {
setup: function(){
App = startApp();
this.xhr = sinon.useFakeXMLHttpRequest();
this.server = sinon.fakeServer.create();
this.server.autoRespond = true;
sinon.spy(Ember.$, 'ajax');
this.server.respondWith('POST', '/oauth/token', [
200,
{ 'Content-Type': 'application/json' },
'{"access_token":"secret token 2!","token_type":"bearer","expires_in":7200}'
]);
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
test('authentication works correctly', function() {
visit('/login').fillIn('#identification', "foo@bar.com").fillIn('#password', "password").click('button[type="submit"]').then(function() {
ok(!exists('a:contains(Login)'), 'Login button is not displayed when authenticated');
});
});
#identification 和#password 输入字段存在,并且提交按钮存在于包含它们的字段上。
我在标题中包含 sinon 和 qunit。我是用错误的方式称呼 sinon 还是犯了其他错误?
编辑:解决方案:通过还包括 sinon-qunit,问题就消失了。如果不包含 sinon-qunit,您似乎无法将 sinon 与 Ember App Kit qunit 测试一起使用。
编辑 2: 我在这里开源了一个示例,其中包含使用 sinon 模拟登录响应的测试:https://github.com/digitalplaywright/eak-simple-auth
【问题讨论】:
-
你能关闭这个问题或者以某种方式标记这个问题已经解决了吗?
-
我很想看看您的解决方案的详细信息。我试图让它工作,但目前如果我在验收测试中多次模拟用户登录,我最终会陷入测试运行的无限循环。
-
当然,我在这里开源了一个使用 sinon 测试的项目:github.com/digitalplaywright/eak-simple-auth
标签: javascript authentication ember.js sinon ember-app-kit