expressjs typescript test

Solutions on MaxInterview for expressjs typescript test by the best coders in the world

showing results for - "expressjs typescript test"
Alissa
10 Jun 2016
1import { expect } from "chai"
2import chai from "chai"
3import chaiHttp from "chai-http"
4chai.use(chaiHttp);
5import express from "express"
6import { createHttpTerminator, HttpTerminatorConfig } from "http-terminator"
7
8const testServer: express.Application = express()
9let serverRef, httpTerminator: any
10describe('Test Description', () => {
11    before(() => {
12        testServer.get('/toto', (req, res) => {
13            res.send('Hello World')
14        })
15        testServer.get('/tata', (req, res) => {
16            res.send('Hello tata')
17        })
18        serverRef = testServer.listen(3000, function () {
19            // console.log('App is listening on port 3000!');
20        });
21        httpTerminator = createHttpTerminator({ server: serverRef });
22
23    })
24    after(async () => {
25        await httpTerminator.terminate();
26    })
27    it('test toto', (done) => {
28        chai.request('http://localhost:3000')
29        .get('/toto')
30        .end(function(err, res) {
31            expect(res).to.have.status(200);
32            expect(res.text).to.eq('Hello World');
33            done(); 
34          });
35    })
36    it('test tata', (done) => {
37        chai.request('http://localhost:3000')
38        .get('/tata')
39        .end(function(err, res) {
40            expect(res).to.have.status(200);
41            expect(res.text).to.eq('Hello tata');
42            done(); 
43          });
44    })
45})