I would like to mock server login responses when testing Ember Simple Auth in my Ember App Kit application. However, with the following code I get an opaque error 'Unexpected end of input' when the click action is called on the visit function :
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');
});
});
The #identification and #password input fields exists, and the submit button exists on the field that contains them.
I am including sinon and qunit in my headers. Am I calling sinon the wrong way or making some other mistake?
Edit: Resolution: By also including sinon-qunit the problem disappeared. It seems like you can not use sinon with Ember App Kit qunit tests without including sinon-qunit.
Edit 2: I open sourced an example with tests that mocks login responses with sinon here: https://github.com/digitalplaywright/eak-simple-auth