import { shallow, ShallowWrapper } from 'enzyme'; import { Mock } from 'ts-mockery'; import { ShlinkApiError, ShlinkApiErrorProps } from '../../src/api/ShlinkApiError'; import { InvalidArgumentError, ProblemDetailsError } from '../../src/api/types'; describe('', () => { let wrapper: ShallowWrapper; const createWrapper = (props: ShlinkApiErrorProps) => { wrapper = shallow(); return wrapper; }; afterEach(() => wrapper?.unmount()); it.each([ [ undefined, 'the fallback', 'the fallback' ], [ Mock.all(), 'the fallback', 'the fallback' ], [ Mock.of({ detail: 'the detail' }), 'the fallback', 'the detail' ], ])('renders proper message', (errorData, fallbackMessage, expectedMessage) => { const wrapper = createWrapper({ errorData, fallbackMessage }); expect(wrapper.text()).toContain(expectedMessage); }); it.each([ [ undefined, 0 ], [ Mock.all(), 0 ], [ Mock.of({ type: 'INVALID_ARGUMENT', invalidElements: [] }), 1 ], ])('renders list of invalid elements when provided error is an InvalidError', (errorData, expectedElementsCount) => { const wrapper = createWrapper({ errorData }); const p = wrapper.find('p'); expect(p).toHaveLength(expectedElementsCount); }); });