柴-http不起作用

时间:2016-11-03 10:57:55

标签: node.js express mocha chai

获取错误未捕获TypeError:无法读取未定义的属性“apply”       在立即。 (node_modules /快递/ LIB /路由器/ index.js:618:14)

服务器和测试文件。

// server js file
'use strict';

var express = require('express');        // call express
var app = express();
var port = process.env.PORT || 8080;

// Routes for schedule API
var router = express.Router();
router.get('/', function(req, res, next) {
    res.json({"msg":'Hello, World!'});
});

app.listen(port);
console.log('Application running on port ' + port);

module.exports=router;

// test.js 
var chai = require('chai');
var chaiHttp=require('chai-http');

var server = require('../server');
var should = chai.should();
chai.use(chaiHttp);
describe('Scheduler', function () {            
    it('should return hello world', function (done) {
        chai.request(server)
            .get('/')
            .end(function (err, res) {
                res.should.have.status(200);
                done();
            };
    });
});

有人可以帮我跟踪这里出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

你可以使用expect而不是它应该更容易

var chai = require('chai'), chaiHttp = require('chai-http');
chai.use(chaiHttp);
var expect = chai.expect;
app.get('/check', function(req, res) {
//exemple
expect(req.query.ip,"IP Adress Mismatch").to.be.an.ip;
}