41 lines
1.0 KiB
TypeScript
Raw Normal View History

import request from "supertest";
import app from "../src/app";
import { Server, IncomingMessage, ServerResponse } from "http";
import * as dotenv from "dotenv";
dotenv.config({path: '../../.env'})
const port = parseInt(process.env.BAR_PORT || '3000')
let serveur : Server<typeof IncomingMessage, typeof ServerResponse>
describe("Test the welcome path", () => {
beforeEach(() => {
serveur = app.listen(port, () =>{
console.log(`serveur running in ${port}`)
})
})
afterEach((done) => {
serveur.close(done)
})
test("It should response the GET method", done => {
request(app)
.get("/welcome")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
test("It should response the GET method", done => {
const out = {hello:"world"};
request(app)
.get("/welcome")
.then(response => {
expect(response.text).toEqual(JSON.stringify(out))
done();
});
});
});