2016-10-12 4 views
1

이 코드는 이중 콜백을 던지고 있습니다! 다음에 오류가 있습니다.더블 콜백! Node.js Chai

TypeError: Cannot read property 'status' of undefined at Assertion. (node_modules\chai\lib\chai\core\assertions.js:890:14) at Assertion.ctx.(anonymous function) [as property] (node_modules\chai\lib\chai\utils\addMethod.js:41:25) at Assertion. (node_modules\chai-http\lib\http.js:80:38) at Assertion.ctx.(anonymous function) [as status] (node_modules\chai\lib\chai\utils\addMethod.js:41:25) at tests\unitTest\helloWorld.js:16:37 at Test.Request.callback (node_modules\chai-http\node_modules\superagent\lib\node\index.js:615:12) at ClientRequest. (node_modules\chai-http\node_modules\superagent\lib\node\index.js:567:10) at Socket.socketErrorListener (_http_client.js:269:9) at emitErrorNT (net.js:1269:8)

오류가 비정상적으로 표시되는 경우가 있습니다.

var chai = require('chai') 
     , chaiHttp = require('chai-http'); 
    chai.use(chaiHttp); 

    var assert = require('assert'); 
    var expect = chai.expect; 
    require('should-http'); 
describe('Array', function() { 
    describe('#indexOf()', function() { 
     it('should return -1 when the value is not present', function(done) { 
      //assert.equal(-1, [1,2,3].indexOf(4)); 
      //console.log("x") 
      chai.request('http://192.168.99.100:8080').get('/hello').end(function (err, res) { 
       expect(res).to.have.status(200); 
       res.text.should.equal('hello world2'); 
       done(); 
      }); 
     }); 
    }); 
}); 

문서 : https://github.com/chaijs/chai-http

+0

어디 서버 인스턴스화 중입니까? 일반적으로 테스트에서는 테스트 중에 서버를 빌드/떼어 내고 테스트 자체 외부에서는 실행하지 않으려 고합니다. 어딘가에 경쟁 조건이 될 수 있습니다. –

+0

로컬에서 실행 –

답변

0

내가 이중 콜백을 볼 수 없습니다! 스택 추적에서 언급 한 오류. 복사하는 것을 잊었을 가능성이 있습니까? 저에게 서버 시간 초과 및 시간 초과 오류가 다시 발생하고 시간 초과가 발생하기 때문에 콜백에서 res var가 정의되지 않은 상태에서 정의되지 않은 var에 액세스하려고하므로 중단됩니다.

this.timeout(4000); 

을하고 인쇄 상황을 확인하기 위해 콜백에서뿐만 아니라 일부 CONSOLE.LOG을 넣어 : 당신은 그런 시험의 제한 시간을 증가시키기 위해 시도 할 수 있습니다. 또한 여러 개의 테스트를 실행하는 경우 다른 테스트를 실행할 때 서버가 충돌하지 않는지 확인하십시오.

0

이 문제가 파일의 새 버전은 서버를 다시 시작 때로는 주소를 변경 때마다 것을 밝혀/포트는 사용할 수 없습니다 :

듣고 - 오류 : EADDRINUSE를 ::: 5858