Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This document is a starting/reference guide for writing unit tests for the UI modules within ERM. 

...

Note: Its very important all the developers understand what each of the mock is actually mocking and also understand the jest configuration within the jest.config.js file. Understanding these details will help us devs debug the tests quickly specially when we hit errors/issues within the tests that are due to stripes level dependencies.

...

const onAdd = jest.fn();
const onSubmit = jest.fn();

const basketSelectorProps = {
'addButtonLabel':'add button',
'autoFocus':true,
'basket':[{
'id':'5650325f-52ef-4ac3-a77a-893911ccb666',
'class':'org.olf.kb.Pkg',
'name':'Edward Elgar:Edward Elgar E-Book Archive in Business & Management, Economics and Finance:Nationallizenz',
'suppressFromDiscovery':false,
'label': 'basketSelector'
}]
};

describe('BasketSelector', () => {
test('renders add To Basket button', () => {
const { getByText } = renderWithIntl(
<TestForm onSubmit={onSubmit}>
<BasketSelector {...basketSelectorProps}/>
</TestForm>
);

   expect(getByLabelText(/basketSelector/i)).toBeInTheDocument();
userEvent.click(getByText('add button'));
expect(onAdd.mock.calls.length).toBe(1);
});
});

...

Once you run the tests locally you should have an artifacts folder genrated generated locally in your app folder.

...

You can go into the specific file to see what lines/functions are missing th the code coverage and can add them to the tests accordingly.

...