2015-10-16 29 views
1

我正在使用superagent-bluebird-promise,以下給出了404錯誤「不能GET/v1/result」。當我通過郵遞員打電話時,確認它有效。我究竟做錯了什麼?superagent-bluebird-promise不能GET

it('should return a result', function(done){ 
    stub.login(userId); 
    request.get('http://localhost:8080/v1/result/') 
    .then(function(res) { 
     console.log(res); 
     expect(res.body).to.have.lengthOf(1); 
    }, function(error) { 
     console.log(error); 
     expect(error).to.not.exist; 
    }) 
    .finally(function(){ 
     stub.logout(); 
     done(); 
    });   
}); 
+0

登錄是異步的嗎?如果您已註銷,您是否收到該頁面? – Bergi

+0

如果我註釋掉stub.login(),我會得到相同的結果。 (Live,如果我沒有登錄,我會得到401而不是404)。 – Kristy

回答

1

的SuperAgent,藍鳥,承諾是基於supertest

假設stub.login設置了一些餅乾,那麼你就需要他們的下一個請求。

因爲你需要一個代理。 (應用程序可以是可選的)

變種劑= request.agent(APP) agent.request(...)

上的代理執行登錄,然後執行請求就可以了。