I'm starting to add acceptance tests to my Ember project. Starting off with one which tries to log-in to my app:
import { test } from 'ember-qunit';
import moduleForAcceptance from '../helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | login');
test('logging in', function(assert){
visit('/login');
andThen(function(){
assert.equal(currentURL(), '/login');
});
fillIn('#login input[name=email]', 'my@email.com');
fillIn('#login input[name=password]', 'password');
click('#login button[type=submit]');
andThen(function(){
assert.equal(currentURL(), '/dashboard');
});
});
But it fails because the AJAX call to my REST API for authentication fails. This works fine when the app is running normally, but not when done through an acceptance test.
I've traced it back to the following error being returned by ember-ajax
:
Ember AJAX Request POST http://ift.tt/2crYm5h returned a 0\nPayload (Empty Content-Type)\n""
My API isn't even getting the call, so this seems to be an error with sending the REST request. I've checked the hash
object in node_modules/ember-ajax/addon/mixins/ajax-request.js
just before it's sent through to the jQuery AJAX method:
{ type: 'POST',
data: { email: 'my@email.com', password: 'password' },
url: 'http://ift.tt/2crYm5h',
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
headers: { Authorization: 'Bearer undefined; PublicKey Ab732Jte883Jiubgd84376HhhndikT6' } }
contentType
is defined. This is also exactly how hash
looks when making the same AJAX call with the app running normally.
So what is there about Ember acceptance tests which would specifically prevent AJAX calls from working? I suspect there's a config or environment property I'm unaware of that I need to change/set to get it working.
I'm running:
- ember-cli: 2.8.0
- node: 4.5.0
- ember-ajax: 2.5.1
- ember-cli-qunit: 3.0.1
- phantomjs: 2.1.7
Aucun commentaire:
Enregistrer un commentaire