Backend NODE JS Unit Testing

Back End Node JS Unit Testing

Introduction

This document will explain what Back End Node js unit testing is and how it works.

Jest.JS

For unit testing , Corva Back End apps use a library called Jest.js

Jest is a great JavaScript testing framework with a focus on simplicity.

It works with projects using: Babel, TypeScript, Node, React, Angular, Vue and others.

This documentation shows the default files for testing on a new Back End app with node.js:

Default Files

The unit file for testing is processor.test.js located in the folder test at the root of the project.

There is only one test function in this file called ‘process event’.

This function is set to always pass, it creates an instance of the processor (declared in src/processor.js) and executes a test function that prints a message to match the receiving fan event like Back End apps usually do.

Code snippet example

Execution

  1. Make sure you have installed node.js dependencies in the project before (npm install)

  2. To execute the testing files we have to run the npm run unit command in the root folder.

  3. We should have the next logs in the console:

Execution

Note: everytime we deploy a new Back End app in dev center npm run unit is executed.
Note: We can create our own test files as needed in the test folder too.