I am new to express and very new to unit testing. Consider the following code:
var express = require('express');
var router = express.Router();
var bookingsController = require ("../controllers/bookings");
router
.route('/')
.get(bookingsController.bookings_get)
.post(bookingsController.bookings_post)
router
.route('/:id')
.get(bookingsController.bookings_get_id)
.put(bookingsController.bookings_put_id)
.delete(bookingsController.bookings_delete_id)
module.exports = router;
What is the right/recommended way of writing unit tests for this? I would like to be able to test, for example, that router.route('/:id')
does not accept POST calls.
I know I can do this with supertest, but I believe that would be considered an integration test as supertest would start the app the run the test.
I've read and tried multiple node.js/express.js testing tutorials but couldn't find an answer to this. Any pointers to existing tutorials most welcome. Direct answers here, even more :)