Loading
Current section: Modules 4 exercises
lesson

Intro to Modules

Loading lesson

Transcript

00:00 Mocking a module should be your last resort, because it's the most intrusive technique out there. It's the highest place where you can draw the test boundary. Remember how we covered that mocking basically comes down to gaining control over values, or behaviors, or both.

00:16 But when you mock a module, you're not just gaining control, you're actually throwing away those two. And now suddenly you become in charge to make sure that that module you mocked functions correctly. In practice, mocking modules harms more than it helps, because it exposes your test to way much of implementation details of what you're mocking.

00:35 You need to make sure that the exports are now correct, that the internals are fine, and you're basically covering different things that may change when you upgrade a dependency, for example. That being said, there are legitimate use cases to do module mocking, and we're going to cover them in this exercise block. But before we do that, let's explore some of the alternative techniques you may use

00:54 before you resort to module mocking.