【发布时间】:2016-09-16 11:18:50
【问题描述】:
我开始向我的 Ember 项目添加验收测试。从尝试登录我的应用程序开始:
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');
});
});
但它失败了,因为对我的 REST API 进行身份验证的 AJAX 调用失败。这在应用程序正常运行时可以正常工作,但在通过验收测试时就不行了。
我已经追溯到ember-ajax返回的以下错误:
Ember AJAX Request POST https://127.0.0.1:8081/login returned a 0\nPayload (Empty Content-Type)\n""
我的 API 甚至没有收到调用,所以这似乎是发送 REST 请求时出错。在将其发送到 jQuery AJAX 方法之前,我已经检查了 node_modules/ember-ajax/addon/mixins/ajax-request.js 中的 hash 对象:
{ type: 'POST',
data: { email: 'my@email.com', password: 'password' },
url: 'https://127.0.0.1:8081/login',
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
headers: { Authorization: 'Bearer undefined; PublicKey Ab732Jte883Jiubgd84376HhhndikT6' } }
contentType 已定义。这也是 hash 在应用正常运行的情况下进行相同 AJAX 调用时的外观。
那么,Ember 验收测试有什么特别会阻止 AJAX 调用工作的呢?我怀疑有一个配置或环境属性我不知道我需要更改/设置以使其正常工作。
我在跑步:
- ember-cli:2.8.0
- 节点:4.5.0
- ember-ajax:2.5.1
- ember-cli-qunit:3.0.1
- phantomjs:2.1.7
【问题讨论】:
标签: ajax ember.js qunit acceptance-testing