@tressie.damore
To test routes using Mocha, you can follow these steps:
1
|
npm install --save-dev mocha supertest |
1 2 3 4 5 6 7 8 9 10 11 |
const request = require('supertest'); const app = require('../app'); describe('GET /api/example', () => { it('responds with json', (done) => { request(app) .get('/api/example') .expect('Content-Type', /json/) .expect(200, done); }); }); |
1
|
npx mocha test/routes.test.js |
This will execute your test cases and display the results in the terminal. If the tests pass, you will see a success message. If there are any failed tests, Mocha will provide details about the errors.
Remember to replace ../app
with the path to your Express application file in the example above.
By following these steps, you can test your routes using Mocha and Supertest in your Node.js Express application.