We use Sinon to mock Typescript modules by using mockModule to create a function that can mock the given module. This is done at the outer-most scope of our test suite so that this
With mocks for dependencies inside functions, unit tests will be resilient to a changing codebase. And functions with mocks can be developed without a chain of dependencies.
I just went through the practice of speeding up a large JavaScript test suite for my project. Here are some of the culprits I found and how I fixed them.