How it works...

In our case, we used the sandbox to stub a method of one of our dependencies. This way, the get method of axios never gets fired and we receive an object that is similar to what the backend will give us.

Stubbing the API responses will get you isolated from the backend and its quirks. If something goes wrong, you won't mind and, moreover, you can run your test without relying on the backend running correctly.

There are many libraries and techniques to stub API calls in general, not only related to HTTP. Hopefully, this recipe has given you a head start.

Get Vue.js 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.