【发布时间】:2019-01-12 01:34:39
【问题描述】:
我正在使用 requestjs 向 API 发出 get 请求,然后在 requestCallBack 中将正文映射到自定义 json 对象。我正在尝试使用 Jest 测试此代码,但无论我如何模拟它,它似乎都不起作用
我已经尝试过request.get.mockImplementation(),这似乎只是模拟 get 并且不允许我测试回调中的代码
await request.get('endpoint', requestOptions, (err, res, body) => { transformBodyContent(body) })
jest.mock('request')
jest.mock('request-promise-native')
import request from 'request-promise-native'
test('test requestCallback code', async () => {
// not sure how to test that bodyTransformer is called and is working
}
【问题讨论】:
标签: javascript jestjs restify request-promise requestjs