I use ember-simple-auth within my application. For my test I use QUnit together with jquery-mockjax. But I didn't get my test, login with correct credentials
, to work with a mocked response. If I didn't mock, the test below works. The mocked response looks exactly like a server response.
My question is, how should I mock the response for ember-simple-auth?
test "with correct credentials", ->
expect(2)
response =
access_token : "92d50f562503e40fe783c2ebf359e0c2b37fa80758e2e3603d7e3e82a485522a"
expires_in : 7200
token_type : "bearer"
# if I remove the following line, the test works
mock_http('/oauth/token', response, 200)
visit("login")
.fillIn('#identification', '[email protected]')
.fillIn('#password', 'tester')
.click('.btn-success').then ->
ok(find("a:contains('Logout')").length, 'logout link not visible')
ok(not find("a:contains('Login')").length, 'login link still visible')
the following test also works with mocking:
test "with wrong credentials", ->
expect(2)
response =
error : 'some error occured'
mock_http('/oauth/token', response, 401)
visit("login")
.fillIn('#identification', 'test')
.fillIn('#password', 'wrong')
.click('.btn-success').then ->
ok(not find("a:contains('Logout')").length, 'logout link not visible')
ok(find("a:contains('Login')").length, 'login link still visible')
EDIT:
Following a jsBin, that shows the problem: http://jsbin.com/ASaSaRiX/6/edit
The problem is caused by jQuery version conflicts with mockjax. With the help from marcoow I found this stackoverflow question. With jQuery < 1.10 it works. Mhh... that's not nice.
By the way a working jsBin: http://jsbin.com/ASaSaRiX/11
EDIT: You can find more detailed information here. The problem is caused by a changed in jQuery.
@marcoow: One fix is to add
dataType: 'json'
to the request options of Ember.SimpleAuth. Maybe you have some time to look at the informations given in the link above.