2017-09-03 7 views
0

로그인 할 때 게시 할 기능이있는 앱을 만들고 있습니다. mocha에 다음 테스트 코드를 작성했습니다.) 나는 (내가 다 사용하여 몇 가지 실수를 생각done()은 슈퍼 에이전트 요청 내에서 작동하지 않습니다.

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

:이 오류가 발생합니다. 다른 모든 단언 문이 통과되었습니다. 제가 잘못 가고있는 곳이나 더 많은 정보가 필요한 경우 알려주십시오.

it("Login and post", function(done) { 
    superagent 
     .post(URL_ROOT + "/register") 
     .send({ 
      email: "[email protected]", 
      password: "posttest" 
     }) 
     .end(function(err, res) { 
      assert.ifError(err); 
      var token = res.body.token; 
      superagent 
       .post(URL_ROOT + "/post") 
       .send({ 
        content: "testing post", 
        user: jwt.decode(token).id 
       }) 
       .set("Authorization", "test_scheme " + token) 
       .end(function(err, res){ 
        assert.ifError(err); 
        assert.equal(res.body.post.content, "testing post"); 
        done(); 
       }); 
     }); 
}); 

답변

0
실행하는 데 2 ​​초 이상을 복용 할 수 귀하의 테스트

이 줄을 추가 바로 superagent .post(URL_ROOT + "/register")...하기 전에, it에 콜백의 첫 번째 줄에서가 :

this.timeout(30000)

이 만에 당신을 수 있습니다 30 초 후에 2 대신에 시간 초과 됨.