【问题标题】:Error timeout after 5000 ms with mongoose jest and superusermongoose jest 和超级用户 5000 毫秒后错误超时
【发布时间】:2020-08-24 11:44:50
【问题描述】:

我正在尝试使用 jest、supertest 和 mongoose 测试端点,但实际上当我尝试使用 supertest 发出请求时,它在 5000 毫秒后给出了超时错误,表明未调用异步回调

// test.js
import supertest from 'supertest';
import mongoose from 'mongoose';

import app from '../../src/index';
import user from '../../src/app/models/user';

const request = supertest(app);

beforeAll(async () => {
  await mongoose.connect('mongodb://localhost:27017/user', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  });
});

it('should list all user', async (done) => {
  const response = await request.get('/');
  expect(response.status).toBe(200);

  done();
});

//index.js
import express from 'express';
import mongoose from 'mongoose';
import routes from './routes';

const app = express();

// mongoose.connect('mongodb://localhost:27017/usersexample', {
//   useNewUrlParser: true,
//   useUnifiedTopology: true,
// });

app.use(express.json());
app.use(routes);

app.listen(3000);

export default app;

【问题讨论】:

    标签: mongodb express testing mongoose jestjs


    【解决方案1】:

    您没有提供足够的信息,由于错误您正在调用一条没有答案的路线,jest 正在寻找终点,但由于他没有或没有找到它最终无限运行。

    【讨论】:

    • 实际上我正在使用路由,并且在 routes.js 它有一个 '/' 的端点,所以应该完成,不是吗?
    • 不,你需要完成答案,我不知道你使用的是哪个库,如果你有“/”路线并且在快递的情况下需要它,你需要将状态和关闭响应作为 .send() 传递
    猜你喜欢
    • 2022-06-14
    • 1970-01-01
    • 2014-03-19
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 2021-05-13
    相关资源
    最近更新 更多