'supertest gets timeout error when I use await in a controller
const express = require('express');
const router = express.Router();
const Product = require('./../model/product');
router
.route('/api/product')
.get(async (req, res) => {
const product = await Product.find({});
console.log(product);
return res.status(200).send({ message: 'ok' });
})
module.exports = { router };
the code above is my controller file
const request = require('supertest');
const { app } = require('./../../app');
it('creates a product and product list is emply', async () => {
await request(app).get('/api/product').expect(200);
});
and this is my test file. when I run the test I receive this error:
thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|