Skip to main content

Unit testing with Jest


Concierge tool supports unit testing of webmodules. Those can be written in TypeScript using Jest as test runner and React Testing Library for testing React components.

Jest framework documentation:

Setting up test configuration for a module

Run the ngv build and ngv test:prepare commands and it will create everything using Concierge tool. Test files should be created in the code/src/test/jest directory and match the *.test.[tsx|ts] filename pattern.

Tests can be run by running the ngv test command in the webmodule’s directory

Basic test structure

Below find general structure of tests for webmodules:

// imports

describe('name of test suite', () => {

    // setup of consts

    it('test case 1', () => {

     it('test case 2', () => {

describe creates a block that groups together several related tests with tests invoked in a callback method.

it defines one test case

Testing component using React Testing Library

import '@testing-library/jest-dom';
import { render, fireEvent, screen } from '@testing-library/react';

it('test description', () => {
    // Given
    const props = { ... };

    // When
    render(<TestComponent {...props} />);'Load test data'));

    // Then
    expect(screen.getByRole('alert')).toHaveTextContent('Oops, failed to fetch!');

More examples (samples with code)

  • Testing asynchronous code with Sabre’s interfaces