I am encountering an issue with the code snippet below in my application
request.ts
import request from 'request'
export const funcA = async ( apiToken: string, body: any): Promise<any> => {
return new Promise((resolve, reject) => {
const options = {
method: 'POST',
url: `https://any_url?api_token=${apiToken}`,
body: {
...body,
},
json: true,
}
request(options, (err, resp, body) => {
if (err) {
log('funcA', err)
reject(err)
} else resolve(body)
})
})
}
test.ts
import { funcA } from '../funcApath'
import request from 'request'
jest.mock('request')
describe('funcA test', () => {
test('should call funcA example', async () => {
const options = await optionsConstructor()
const mockRequest = await request(options)
const body = await bodyConstructor()
const apiToken = 'any_apiToken'
const result = await funcA(apiToken, body)
expect(mockRequest).toHaveBeenCalledTimes(1)
})
})
Here is the error I encountered:
Error: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
I have attempted using the "beforeEach function" but without success. Any suggestions on how to resolve this issue? Thank you!!