I have a TypeScript source file that has the following import:
// myCode.ts
import * as x from 'dep';
...
export class myClass {
...
}
where dep is a Node package that's included as part of the npm install. myCode.ts is a simple class that just has three methods. I would like to mock the entire myClass from inside a Jest test script that is written to test another class, myMainClass.
The problem I'm having is that the dep code is running some initialization that I can't seem to bypass. The initialization code fails outside the "real" environment so I simply want to bypass this for test purposes. No matter what I try I get an error that looks something like this:
Test suite failed to run
Dynamic Linking Error: ... error text ...
5 | // myCode.js
> 6 | import * as x from 'dep';
| ^
Again, the error is expected since I don't have these libraries locally (and don't want them for unit testing).
I was hoping I could add a simple mock statement (e.g., jest.mock('myClass'), or something similar, that would bypass anything to do with myClass. That way the code causing the link error would not be executed.
I'm fairly new to using Jest. Hopefully, this is a simple ask and I'm just missing the obvious. Thanks for the help.