UNPKG

1.21 kBPlain TextView Raw
1import { expect } from 'chai';
2import { express } from '.';
3
4describe('express', () => {
5 describe('routes', () => {
6 it('list routes', () => {
7 const router = express.router();
8 router.get('/foo', (req, res) => true);
9 router.get('/foo/:id', (req, res) => true);
10 router.put('/foo/:id', (req, res) => true);
11 router.post('/foo/:id', (req, res) => true);
12 router.delete('/foo/:id', (req, res) => true);
13 router.patch('/foo/:id', (req, res) => true);
14
15 const res = express.routes(router);
16 expect(res.length).to.eql(2);
17
18 expect(res[0].path).to.eql('/foo');
19 expect(res[0].methods).to.eql(['GET']);
20
21 expect(res[1].path).to.eql('/foo/:id');
22 expect(res[1].methods).to.eql(['GET', 'PUT', 'POST', 'DELETE', 'PATCH']);
23 });
24
25 it('has no routes', () => {
26 const router = express.router();
27 const res = express.routes(router);
28 expect(res).to.eql([]);
29 });
30
31 it('has no methods on a route', () => {
32 const router = express.router();
33 router.get('/foo');
34 const res = express.routes(router);
35 expect(res.length).to.eql(1);
36 expect(res[0]).to.eql({ path: '/foo', methods: [] });
37 });
38 });
39});