我的应用程序概述:
以下是我的代码:
Server.js
'use strict';
var express = require('express');
var app = express();
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(__dirname + '/public'));
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
var port = process.env.OPENSHIFT_NODEJS_PORT || 3000; //6969;
var services = {},
config = require('./middleware/api/config')(process.env);
require('./middleware/api')(app, services, config);
console.log('Express server listening on port ' + port);
var server = app.listen(port, ipaddress);
module.exports = server;
test.js:
var chai = require('chai');
var chaiHttp = require('chai-http');
var should = chai.should();
var expect = require('chai').expect;
var server = require('../');
chai.use(chaiHttp);
chai.should();
describe("Booking Tests", function(){
it("A Booking should be made on api/booking/ POST", function(done){
chai.request(server)
.post('/api/booking')
.send({"purpose": "Purpose 4", "startDate": "2016-03-20", "endDate": "2016-03-22", "startTime": "01:30", "endTime": "03:30", "requestor": { "email": "XXX@gmail.com" }, "roomNumber": "111"})
.end(function(err, res){
res.should.have.status(200);
res.should.be.json;
done();
})
});
});
测试报告:
<testsuite name="Mocha Tests" tests="2" failures="1" errors="1" skipped="0" timestamp="Sun, 27 Mar 2016 05:18:21 GMT" time="0.049">
<testcase classname="Booking Tests" name="A Booking should be made on api/booking/ POST" time="0.04"/>
<testcase classname="Booking Tests" name="A Booking should be made on api/booking/ POST" time="0.04"/>
</testsuite>
测试 - “应该在api / booking / POST上进行预订”运行两次。在我的测试文件中只有一个测试,但报告显示2个测试执行 - 1个通过,1个失败。 请让我在哪里出错。