Testing
falcon-client exposes FalconClientMock component which allows you to setup application context inside unit test environment.
FalconClientMock can receive props for mock version of React context provider components used by falcon-client internally:
apollo: object- props forMockProvidercomponent fromreact-apollorouter: objectprops forMemoryRoutercomponent fromreact-router-domasyncComponent: object- props forAsyncComponentProvidercomponent fromreact-async-componenti18next: object- props forI18nextProvidercomponent fromreact-i18nexthelmet: object- props forHelmetProvidercomponent fromreact-helmet-async
Tests should be named [component].test.js.
Under the hood FalconClientMock uses Jest and has access to all the same mock functions.
Running Tests
Tests can be run in the command line from your client directory using npm or yarn. This will run all tests.
- NPM
- Yarn
npm test
yarn test
Options
Running the test command will run all tests, you will then have access to the following options:
- Press
ato run all tests. - Press
fto run only failed tests. - Press
oto only run tests related to changed files. - Press
pto filter by a filename regex pattern. - Press
tto filter by a test name regex pattern. - Press
qto quit watch mode. - Press
Enterto trigger a test run.
Usage
In this example we are testing the Banner component.
describe() expects 2 arguments, name and fn.
name will appear in your console to help you identify the tests, we advise using the component name here.
describe('<Banner />', ...

Inside the function (fn) passed to describe you can run your tests.
We advise familiarizing yourself with Jest before writing tests.
Banner.test.js
import React from 'react';
import ReactDOM from 'react-dom';
import { FalconClientMock } from '@deity/falcon-client/test-utils';
import { Banner } from './Banner';
describe('<Banner />', () => {
const div = document.createElement('div');
test('Renders correct content', () => {
ReactDOM.render(
<FalconClientMock>
<Banner />
</FalconClientMock>,
div
);
expect(div.innerHTML).toEqual(expect.stringContaining('<p>Banner</p>'));
});
});
In this simple test we check that the <Banner /> component renders <p>Banner</p>.