Skip to main content

Tests

Overview

Concierge supports unit testing of Web Modules. Unit test files should be placed in the src/test/jest folder and end with the .test.ts or .test.tsx suffix.

Tests are written in TypeScript using:

Running Tests

Execute the following command in the Web Module folder to run unit tests:

ngv test

This takes care of building or rebuilding Web Module and running unit tests.

Unit Test Structure

The general structure of Jest unit tests:

// Imports

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

    // Setup of constants

    it('test case 1', () => {
        //Given-When-Then
    });

    it('test case 2', () => {
        //Given-When-Then
    });
});

Using React Testing Library

Testing component using React Testing Library:

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

describe('React Testing Library Suite', () => {

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

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

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

Example

An example of unit tests with comments can be found in com.sabre.redapp.example3.web.wf.extension sample.