diff --git a/test/api/ShlinkApiError.test.tsx b/test/api/ShlinkApiError.test.tsx index aad32f72..fe04fe47 100644 --- a/test/api/ShlinkApiError.test.tsx +++ b/test/api/ShlinkApiError.test.tsx @@ -1,26 +1,20 @@ -import { shallow, ShallowWrapper } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { ShlinkApiError, ShlinkApiErrorProps } from '../../src/api/ShlinkApiError'; import { InvalidArgumentError, ProblemDetailsError } from '../../src/api/types'; describe('', () => { - let commonWrapper: ShallowWrapper; - const createWrapper = (props: ShlinkApiErrorProps) => { - commonWrapper = shallow(); - - return commonWrapper; - }; - - afterEach(() => commonWrapper?.unmount()); + const setUp = (props: ShlinkApiErrorProps) => render(); 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 }); + const { container } = setUp({ errorData, fallbackMessage }); - expect(wrapper.text()).toContain(expectedMessage); + expect(container.firstChild).toHaveTextContent(expectedMessage); + expect(screen.queryByRole('paragraph')).not.toBeInTheDocument(); }); it.each([ @@ -28,9 +22,7 @@ describe('', () => { [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); + setUp({ errorData }); + expect(screen.queryAllByText(/^Invalid elements/)).toHaveLength(expectedElementsCount); }); });