top of page

Integration Tests under Node.js Environment using a mock server

Updated: Jun 27, 2019

This week, I was handed a nice task – to integrate with some external service we use, that has no API. All communication with the service was supposed to be mimicking a multiple step scenario of a user integrating with some forms. This means, cookies, sessions, and all the wonders of HTTP protocol..

And, just to add giggles, the whole component is to be written in and act as a part of a NodeJS server.

So, I thought to myself, first thing first; I configured a new NodeJs project with a Jasmine test environment, and started writing my integration tests.

But unfortunately, not only my remote service had no API, there was no way I could create an embedded local service for me to test against!

Popped up Fiddler (or Charles, whatever..) and sniffed the HTTPS traffic as I filled in the forms (Fiddler does it quite elegantly), and created a spec, specifying how should each and every packed look like.

To test it, I created a little HTTP service module, that can store its last request and even stub a response behavior.

It supports HTTP and HTTPS, and made my life easy.

Here is some usage examples:

Setting it up:

And making the actual test:


bottom of page