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-qunit も含めることで、問題は解消されました。sinon-qunit を含めないと、Ember App Kit の qunit テストで sinon を使用できないようです。
編集 2:ここで sinon を使用してログイン応答をモックするテストを使用して例をオープン ソース化しました: https://github.com/digitalplaywright/eak-simple-auth