Open simonespa opened 1 year ago
My workaround to make TypeScript happy was to extend the definition of the library by declaring the following:
declare module 'aws-embedded-metrics' {
const mockLogger: {
setNamespace: (value: string) => MetricsLogger;
setDimensions: (dimensionSet: Record<string, string>) => MetricsLogger;
setProperty: (key: string, value: unknown) => MetricsLogger;
putMetric: (key: string, value: number, unit?: Unit | string) => MetricsLogger;
};
}
By doing so I can use the mockLogger
object returned by the stubbed library.
I also tried other approaches to pass the "mockLogger" without being part of the aws-embedded-metrics
to avoid any TypeScript complaint. Unfortunately, the fact that Jest hoists the jest.mock
definition doesn't help.
Context
I'm using this library to send metrics via the
metricScope
and I need to test the functionality. To do so I'm following the example described here https://github.com/awslabs/aws-embedded-metrics-node/blob/master/examples/testing/tests/module.jest.test.js.The project is written in TypeScript and I use jest for unit testing.
Issue
This example https://github.com/awslabs/aws-embedded-metrics-node/blob/master/examples/testing/tests/module.jest.test.js fails in a TypeScript context with the following error:
Question
mockLogger
to the test function without making TypeScript complain?