이 코드는 이중 콜백을 던지고 있습니다! 다음에 오류가 있습니다.더블 콜백! 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
어디 서버 인스턴스화 중입니까? 일반적으로 테스트에서는 테스트 중에 서버를 빌드/떼어 내고 테스트 자체 외부에서는 실행하지 않으려 고합니다. 어딘가에 경쟁 조건이 될 수 있습니다. –
로컬에서 실행 –