O'Reilly logo

Hands-On Microservices with Node.js by Diogo Resende

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

Using chai

We also need to make a little change to our microservice. We need to export its app so that the HTTP plugin from chai can load it and were able to test it without the need to run in a separate console. Add this to the end of our microservice file:

module.exports = app;

You should have a folder hierarchy similar to the following screenshot:

We should now change our image-upload.js test file to create our first real test:

const chai  = require("chai");const http  = require("chai-http");const tools = require("../tools");chai.use(http);describe("Uploading image", () => {    beforeEach((done) => {        chai        .request(tools.service) .delete("/uploads/test_image_upload.png") ...

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