Very simple Jest sample - NextensArelB/SwaggerGenerationTool GitHub Wiki

[[TOC]]

##Introduction

It is a good practice to start with an very simple example and then start to extend to your needs. Here we have an very simple example to start with after you completed the setup instructions.

##sample

As an sample this is our Javascript function:

function sum(a, b) {
    return a + b;
  }
  module.exports = sum;

We can write and Unittest to test this function like this:

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(2, 2)).toBe(4);
});

Here we give the test an title: "adds 1 + 2 to equal 3" and the execution being: expect(sum(2, 2)).toBe(4).

##Test execution To execute this test you can do this with the command:

npm test

The output will look like this:

> @ test C:\Development\Jest sample
> jest

 PASS  ./sum.test.js
  √ adds 1 + 2 to equal 3 (2 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.798 s
Ran all test suites.
⚠️ **GitHub.com Fallback** ⚠️