Write Tests for the Service
Understand how to write unit tests for Firebase Cloud Function services using Mocha, Chai, and Sinon. Discover techniques to mock API calls, handle errors with stubs, and run tests that validate service behavior, ensuring more reliable cloud-native applications.
We'll cover the following...
In this lesson, following best practices, we are going to write a test for the new cross-post-to-devto service. Some people prefer a separate test directory, while others like their test files located next to the production code itself. We will take a “keep-my-tests-close-to-the-code” approach in this course. The concepts you will learn apply regardless of where the tests are located, and you can follow your own preference.
Writing test
All paths and commands below are relative to
services/web/firebase/functions.
Start by installing three necessary NPM packages:
npm i -D mocha chai sinon
Each of these dependencies can easily be covered in three separate courses. Please visit their websites for ...