From the course: Node.js: Testing and Code Quality

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Replacing code with test doubles

Replacing code with test doubles

- [Presenter] Unit testing requires isolation of the target code. However, due to the power of (faintly speaking) Modularity, pretty much, everything depends on everything. How can we isolate our code, so we only test the intended functionality? There's a solution to this problem, and it involves replacing and inspecting code execution with test structures, known as stubs, spies and mocks. In this chapter, we're going to start by discussing what Test Doubles are, and how they can be used to replace code. Then, we'll compare some techniques for overriding dependencies by manipulating the required cash. With that foundation, we'll apply these techniques to our testing. We'll control the responses of methods, observe interactions between components and verify expected behavior of the code we're testing. We'll do all of this, without having to modify how our modules require code, which is fantastic. Let's start by…

Contents