How to do Firebase, NodeJS, ExpressJS API endpoint unit tests?

almantas88

almantas88

Posted on February 19, 2021

How to do Firebase, NodeJS, ExpressJS API endpoint unit tests?

I'm lost, I have been searching for good resources but I can't find any. How to do unit testing for a back-end NodeJS, ExpressJS, Firestore, RESTful app? What tools to use? How to mock data? I don't want to have a test database for testing, I want to mock data. Can any one help me?

Example of an endpoint:

router.post("/color", async (request, response) => { 

    if(Object.keys(request.body).length === 0) return response.status(406).send("Ups... There was missing data.");

    try {
        await db.collection('Colors').add({
            realColor: request.body.realColor,
            colorMap: request.body.colorMap
        });
        response.status(201).send("Success! A color was creted!");
    }
    catch (error) {
        console.log(error);
        response.status(400).send("Ups... A color was NOT creted!");
    }
});
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
almantas88
almantas88

Posted on February 19, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related