awslabs / awslabs/aws-embedded-metrics-node

"no exported member 'mockLogger'" error when mocking the library in TypeScript

Open
#139 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
263
Forks
39
PR merge metrics
No merged PRs in 30d

Description

## 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:

```
Module '"aws-embedded-metrics"' has no exported member 'mockLogger'.ts(2305)
```

## Question

* How do I expose the `mockLogger` to the test function without making TypeScript complain?
* Is there a different approach to mock the logger and expose it to the test?

Contributor guide

Open the contributing guide

Research direction

Start with examples/testing/tests/module.jest.test.js and reproduce the TypeScript error that mockLogger is not exported. Then inspect the library's TypeScript exports and declarations to determine how the testing logger is exposed. Done means the example can access mockLogger without a TypeScript export error, or the supported alternative is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.