2014-10-01 2 views
0

node app.js을 실행하면 모든 항목이 시작되도록 응용 프로그램이 제대로 구성되어 있습니다. 내가 단위 테스트를 사용하여 응용 프로그램의 연결이 제대로 작동하는지 테스트하려고합니다. 내가 지금까지있는 것은 : 나는 내가 var options을 추가 왜 오류 메시지 Error: options.uri is a required argument을 얻고 있었다express, nodeJS 및 Mocha를 사용하여 응용 프로그램 연결을 테스트하는 방법

var options = { 
    url: 'http://localhost', 
    port: 8080, 
}; 
var app = require("../app.js"); 
var should = require('should'); 
var assert = require("assert"); 
var async = require('async'); 

it ('tests the ok connection of the app by checking that it is listening on port 8080', function(dont) { 
    request(options,app) 
    .get('/') 
    .expect(200) 
    .end(function (err, res) { 
    res.header['location'].should.include('/') 
    res.text.should.include('Listening on port 8080'); 
    done(); 
    }); 
}); 

. 이제 오류 메시지 TypeError: Object #<Request> has no method 'get'이 표시됩니다.

올바른 연결 (200), 올바른 페이지 ('/') 및 연결시 메시지 Listening on port 8080 로깅을 제대로 확인하는 방법은 무엇입니까?

감사합니다.

+0

옵션없이 '요청 (app)'만 사용해야합니다. 또한'should '에는'.include'가 없으며'.containEql'을 사용해야합니다. –

답변

0

TypeError의 경우 과 같은 것이 아닌 supertest을 사용하고 있는지 확인하십시오. 그 이유는 모듈 request.expect() 및 기타 기능을 제공하지 않기 때문입니다.

+1

downvote를 설명하는 데 관심이 있습니까? – mscdex

+0

답장을 보내 주셔서 감사합니다. -''/ ''페이지를 방문하면 html을 표시하고 싶습니다. 따라서,'app.get ('/ user', function (req, res) {res.send (200);});'과 같은 것을 사용하는 것이 좋을지 모르겠다. 내가 보여주고 싶은 html 대신에 뭔가. 그러면 방문 페이지에 무엇이 있는지 테스트 할 수 있습니까? – maudulus