Member-only story

Integration Tests in Node.js

Discussing a basic setup for Mocha to run integration tests

Pavol Kögler
Better Programming
6 min readJul 29, 2019

In the previous piece, I wrote about the importance of unit tests and how it improved our codebase.

But, what if you want to have more security and also write integration tests in a Node.js application? In this piece, I will discuss a basic setup for Mocha to run integration tests.

While creating examples for this piece, I focused on issues I had in one of my projects. In this project, we had a big REST API application which had hardly any tests at all.

However, there was one important interface and one of the previous developers decided it was important to test it, because it was crucial for the client’s company not to go out of business.

If anything else crashed, we did not worry too much about it but this one was pretty much the end of the world.

The test setup we had was far from perfect. The issue was that the test ran on a real database and created real items on it. These items needed to be removed with a cleanup process.

The cleanup was failing quite regularly and then this product crashed the next test runs because of constraint violations. We needed to manually remove this product.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Pavol Kögler
Pavol Kögler

Written by Pavol Kögler

Fullstack developer and JavaScript enthusiast

Responses (1)

Write a response