Skip to content

Instantly share code, notes, and snippets.

@chemax
Last active May 15, 2020 17:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chemax/69cf1e2a91dd5c1c789f9f6b51ec7646 to your computer and use it in GitHub Desktop.
Save chemax/69cf1e2a91dd5c1c789f9f6b51ec7646 to your computer and use it in GitHub Desktop.
require('dotenv').config();
const lg = require('./libs/log');
const express = require('express');
const app = express();
const mainRouter = require('./libs/router');
app.use('/', mainRouter);
let port = process.env.WEB_PORT || 8080;
app.listen(port, function () {
lg.debug('app listening on port %i!', port);
});
$ npm test
> backend-core@0.0.1 test C:\projects\freeswitch\backend-core-js
> mocha
[2018-10-15T00:00:40.719] [DEBUG] imager - app listening on port 8080!
directory
/GET directory
1) should GET 200 ok
0 passing (24ms)
1 failing
1) directory
/GET directory
should GET 200 ok :
TypeError: app.address is not a function
at serverAddress (node_modules\chai-http\lib\request.js:282:18)
at new Test (node_modules\chai-http\lib\request.js:271:53)
at Object.obj.(anonymous function) [as get] (node_modules\chai-http\lib\request.js:239:14)
at Context.it (test\directory.js:15:18)
const express = require('express');
const router = express.Router();
//Тупо копипаста из примера, чтобы под рукой было
router.use(function timeLog(req, res, next) {
console.log('Time: ', Date.now());
next();
});
router.get('/', function(req, res) {
res.send('Birds home page');
});
// define the about route
router.get('/about', function(req, res) {
res.send('About birds');
});
module.exports = router;
process.env.NODE_ENV = 'test';
let chai = require('chai');
let chaiHttp = require('chai-http');
let server = require('../app');
let should = chai.should();
chai.use(chaiHttp);
describe('directory', () => {
describe('/GET directory', () => {
it('should GET 200 ok ', (done) => {
chai.request(server)
.get('/about')
.end((err, res) => {
res.should.have.status(200);
done();
})
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment