Testing is one of the most important things you can do your code. However, when using a library that requires access to a remote system unit testing can become problematic. You don’t want to have to have a real connection and pull down real data since this is slow and requires anyone contributing to your project to set up the remote system as well. This is where mocking comes in with Jest.
Mocking allows you to detach a module from making a remote call and allows you to define the data that it returns. This means that you can modify the data how you need to provide a small data set or a large data set or even error out on demand.
In this post, we’re going to look at how to set up mocking for JSforce to test logging in and mocking out making queries.