O'Reilly logo

React 16 Tooling by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required