I have an application tested by Mocha and I'm able to successfully run my tests with what I have now, but I'm explicitly setting a GET
route to /api/v1
within my test file. Here's the test file...
API.js
:
var request = require('supertest');
var express = require('express');
var app = express();
var router = express.Router();
app.get('/api/v1', function (req, res, next) {
res.json({
"Hello": "World"
});
});
describe('API', function () {
it("Says 'Hello' is 'World'", function (done) {
request(app)
.get('/api/v1')
.expect('Content-Type', /json/)
.expect(200, {
Hello: 'World'
}, done);
});
});
Have you noticed how I say app.get()
after the require()
statements? I don't want to do that here. I want to be able to import my routes from the routes
directory of my project.
I find it hard to believe that I'm supposed to duplicate all of these routes in my test file. How would I want to import the routes from the routes
directory for use in this testing file?