DEV Community

Discussion on: How to mock an imported Typescript class with Jest

Collapse
 
bmitchinson profile image
Ben Mitchinson • Edited

What took me forever to realize is the jest.mock has to be done above the describe block.

additionally, instead of using this library, I now use

const mockMyClass = MyClass as jest.MockedClass<
            typeof MyClass
        >;

Enter fullscreen mode Exit fullscreen mode

Update: I now use the following method: dev.to/bmitchinson/mocking-classes...