【发布时间】:2020-12-16 21:53:01
【问题描述】:
我没有调用外部 API 端点,我只是想用 supertest/jest 测试我自己的本地端点。设置超时显然不会解决我的问题,因为这是一个非常简单的请求。我正在按此请求调用完成,所以我不明白这里有什么问题。
router.get('/photo', Photo.getFromRequest, function (request, res) {
// making this simple just for the first step
return res.status(200).send
})
jest.mock('../models/photo', () => ({
getFromRequest: jest.fn().mockReturnValueOnce({ id: xxx })
}))
const photo = require('./photo')
const request = require('supertest')
const express = require('express')
const app = express()
app.use('/', photo)
describe('validate photo endpoint', () => {
it('returns 200 and object photo link/image', function (done) {
request(app)
.get('/photo')
// assert things later
.end(function (err, res) {
done(err)
})
})
})
: Timeout - Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout.Error:
【问题讨论】:
-
在该示例中,没有中间件会失败,因为您从不发送响应 - 您在
.send上缺少括号。请注意,您不需要来自中间件的模拟返回值 - 不使用返回值。 -
好地方,但仍然失败..
-
出于同样的原因?请更新以提供minimal reproducible example。
标签: node.js express jestjs timeout supertest