In my Jest test file with a .spec.js extension, I am importing an index.js file that I need to test.
Here is the code snippet from the .spec.js file:
var HttpService = require('./index.js').HttpService;
The problem arises because the index.js file imports a .ts file that contains errors. Although this doesn't affect the project directly (and I cannot modify the .ts file), when running my Jest test,
I encounter errors from the imported .ts file!
This is how the index.js file imports the service-factory.ts file:
var service_factory = require('../service-factory.ts');
And here is a snippet from the service-factory.ts file:
import Loglevel from 'loglevel';
The specific errors I face are:
ERROR:
Cannot find module 'loglevel' or its corresponding type declarations
;
window.App.services
ERROR:
Property 'App' does not exist on type 'Window &typeof globalThis'
These errors are triggered when attempting to run my test, pointing back to the .ts file...
If anyone has advice on resolving this issue, it would be greatly appreciated! Thank you