From 43302ef5a8cff3dd7ee5f30a752fd0ac6f69aaf0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 6 May 2022 21:24:16 +0200 Subject: [PATCH] Migrated ShlinkLogo test to react testing library --- test/common/img/ShlinkLogo.test.tsx | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/test/common/img/ShlinkLogo.test.tsx b/test/common/img/ShlinkLogo.test.tsx index 09793371..d1c6cc61 100644 --- a/test/common/img/ShlinkLogo.test.tsx +++ b/test/common/img/ShlinkLogo.test.tsx @@ -1,25 +1,17 @@ -import { shallow, ShallowWrapper } from 'enzyme'; +import { render } from '@testing-library/react'; import { ShlinkLogo, ShlinkLogoProps } from '../../../src/common/img/ShlinkLogo'; import { MAIN_COLOR } from '../../../src/utils/theme'; describe('', () => { - let wrapper: ShallowWrapper; - const createWrapper = (props: ShlinkLogoProps) => { - wrapper = shallow(); - - return wrapper; - }; - - afterEach(() => wrapper?.unmount()); + const setUp = (props: ShlinkLogoProps) => render(); it.each([ [undefined, MAIN_COLOR], ['red', 'red'], ['white', 'white'], ])('renders expected color', (color, expectedColor) => { - const wrapper = createWrapper({ color }); - - expect(wrapper.find('g').prop('fill')).toEqual(expectedColor); + const { container } = setUp({ color }); + expect(container.querySelector('g')).toHaveAttribute('fill', expectedColor); }); it.each([ @@ -27,8 +19,12 @@ describe('', () => { ['foo', 'foo'], ['bar', 'bar'], ])('renders expected class', (className, expectedClassName) => { - const wrapper = createWrapper({ className }); + const { container } = setUp({ className }); - expect(wrapper.prop('className')).toEqual(expectedClassName); + if (expectedClassName) { + expect(container.firstChild).toHaveAttribute('class', expectedClassName); + } else { + expect(container.firstChild).not.toHaveAttribute('class'); + } }); });