测试运行一秒钟后,Jest没有退出(没有猫鼬)

时间:2019-04-26 13:27:19

标签: node.js unit-testing express jestjs

我试图写一个简单的案例,其中我要打一条路线并检查响应。

我的测试有效,但每次也会抛出此味精:

shape = MySlider.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlColumnStacked, 40, 40, 500, 500);

这是我的单元测试:

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.

这是我的index.ts:

 // 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();
});

1 个答案:

答案 0 :(得分:0)

您尝试过这个吗?我希望这种方式可以解决您的问题。

describe('GET / ', () => {
  test('Test sample get', async () => {
    const response: any = await request(index).get('/');    
    expect(response.text).toEqual('Welcome to Minos');
    expect(response.statusCode).toBe(200);
  }, 20000);
});

使用异步/等待方法也不需要done