Blog
Three lines of Typescript with Jest to Get Typesafe Mocks
A quick TypeScript snippet for getting typesafe Jest mocks so TypeScript won't complain when you access mock-specific methods on mocked imports.
Jan 14, 2020

First the three important lines for anyone who needs to copypaste. I'll explain later!
Now a bit of explanation. When you use jest to mock an import (which I am still not convinced is a good pattern) the mock is still typed as the original import. This means that Typescript will complain if you do something like MockedImport.mocks.
Below is an example setup where this would be useful
If you need to mock implementation
/Contact Us

Modernize your legacy with Focused
Get in touch