2016-09-16 224 views
1

我開始爲我的Ember項目添加驗收測試。出發與一個它試圖登錄到我的應用程序:Ember驗收測試不適用於AJAX

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]', '[email protected]'); 
    fillIn('#login input[name=password]', 'password'); 
    click('#login button[type=submit]'); 

    andThen(function(){ 
    assert.equal(currentURL(), '/dashboard'); 
    }); 
}); 

但由於AJAX調用我的REST API進行身份驗證失敗,失敗。當應用程序正常運行時,此功能正常工作,但通過驗收測試完成後無法正常工作。

我追查回用ember-ajax返回以下錯誤:

Ember AJAX Request POST https://127.0.0.1:8081/login returned a 0\nPayload (Empty Content-Type)\n"" 

我的API甚至沒有得到調用,因此這似乎是與發送REST請求的錯誤。我檢查了hash對象node_modules/ember-ajax/addon/mixins/ajax-request.js之前它通過發送到jQuery的AJAX方法:

{ type: 'POST', 
    data: { email: '[email protected]', 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呼叫工作?我懷疑有一個配置或環境屬性,我不知道,我需要改變/設置讓它工作。

我運行:

  • 燼-CLI:2.8.0
  • 節點:4.5.0
  • 燼的Ajax:2.5.1
  • 燼-CLI-qunit:3.0 0.1
  • phantomjs:2.1.7

回答

1

多麼eejit!我的本地REST API具有無效的SSL證書。所以我只需要告訴PhantomJS忽略我的testem.js文件中的SSL錯誤:

"phantomjs_args": [ 
    "--ignore-ssl-errors=true" 
],