Я пытаюсь написать простой случай, когда я нажимаю на маршрут и проверяю ответ.
Мои тесты работают, но каждый раз также выдает это сообщение:
Jest did not exit one second after the test run has completed.This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
Здесьмой юнит тест:
// we will use supertest to test HTTP requests/responses
import request = require('supertest');
import bodyParser1 = require('body-parser');
// we also need our app for the correct routes!
const index = require('./index');
index.use(bodyParser1.json());
index.use(bodyParser1.urlencoded({ extended: true }));
describe('GET / ', () => {
test('Test sample get', async done => {
const response: any = await request(index).get('/');
expect(response.text).toEqual('Welcome to Minos');
expect(response.statusCode).toBe(200);
done();
});
});
afterAll(async done => {
done();
});
а вот мой index.ts:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => {
//res.setHeader('Content-Type', 'text/html');
res.send('Welcome to Minos');
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
module.exports = app;