1

我正在使用 superagent-bluebird-promise,下面给出了 404 错误,“无法获取 /v1/result”。当我通过邮递员调用它时,已经确认它有效。我究竟做错了什么?

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();
    });         
});
4

1 回答 1

1

superagent-bluebird-promise 基于 supertest

假设 stub.login 设置了一些 cookie,那么您将在下一个请求中需要它们。

为此,您需要一个代理。(应用程序可能是可选的)

var agent = request.agent(app) agent.request(...)

在代理上执行登录,然后也在其上执行请求。

于 2017-06-12T13:38:47.393 回答