I have the following code
export default function monitoring: Monitoring) {
async function GET(req: express.Request, res: express.Response, next: express.NextFunction) {
// Create a custom histogram metric
const httpRequestTimer = monitoring.getHttpRequestDuration();
const end = httpRequestTimer.startTimer();
and I am trying to use sandbox to mock the monitoring class and httpRequestTimer.startTimer();
So I wrote
beforeEach(() => {
monitoring = <Monitoring><unknown>({
getHistagram: () => {},
getPromClient: () => {},
getHttpRequestDuration: ()=>{}
});
GET = status(monitoring).GET;
});
it('Should return status call when xxx is not finished and pages are 0', async () => {
const searchMetadata = {
details: {},
id: `111`
};
const metadata = {
result_count: 0
};
sandbox.mock(monitoring).expects('getHttpRequestDuration').resolves({
startTimer: () => {}
});
await GET(request, res);
});
As soon as I run it I get
1) test status API
Should return status call when xxx is not finished and pages are 0:
TypeError: httpRequestTimer.startTimer is not a function
Also when I console.log(httpRequestTimer) I see
Promise { { startTimer: [Function: startTimer] } }
Any idea how I can mock this scenario?