我想在我的Ember App Kit應用程序中測試Ember Simple Auth時模擬服務器登錄響應。然而,用下面的代碼我得到一個不透明的錯誤「輸入意外結束」時,點擊行動呼籲訪問功能:在Ember App Kit中使用sinon測試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', "[email protected]").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,問題消失了。看起來你不能使用Ember App Kit qunit測試的sinon而不包括sinon-qunit。
編輯2:我開源與測試,嘲笑與興農這裏登錄響應的示例:https://github.com/digitalplaywright/eak-simple-auth
可以關閉這個問題,然後或以某種方式紀念這一解決? – marcoow
我很想看到你的解決方案的細節。我試圖讓它起作用,但是現在如果我在驗收測試中多次嘗試登錄一個用戶,最終會導致無限循環的測試運行。 – David
當然,我在這裏使用sinon測試開源項目:https://github.com/digitalplaywright/eak-simple-auth –