Working with mocks

When you write unit tests, you're testing your own code. At least that's the idea. In reality, this is more difficult than it sounds because your code will inevitably use a library of some sort. This is code that you do not want to test. The problem with writing unit tests that call other libraries is that they often need to reach out to the network or the filesystem. You definitely don't want false positives as a result of side-effects from other libraries.

Jest provides a powerful mocking mechanism that's easy to use. You give Jest the path to a module that you want to mock, and it handles the rest. In some cases, you don't need to provide a mock implementation. In other cases, you need to handle parameters and return ...

Get React 16 Tooling now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.