From cc85b1694ca3cdc4180eb729d2f48c345329509b Mon Sep 17 00:00:00 2001 From: Anastasia Lanz Date: Sat, 3 Feb 2024 16:15:33 -0600 Subject: [PATCH 1/5] fix: collect coverage and setup paths --- packages/react/jest.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/jest.config.ts b/packages/react/jest.config.ts index 74b63303c..0668bc568 100644 --- a/packages/react/jest.config.ts +++ b/packages/react/jest.config.ts @@ -2,13 +2,13 @@ import type { Config } from 'jest'; const config: Config = { testEnvironment: 'jsdom', - setupFilesAfterEnv: ['__tests__/setupTests.ts'], + setupFilesAfterEnv: ['/__tests__/setupTests.ts'], testMatch: [ '**/__tests__/src/**/*.js', '**/__tests__/demo/**/*.js', '**/src/components/**/*.test.tsx' ], - collectCoverageFrom: ['src/**/*.{ts.tsx}'], + collectCoverageFrom: ['/src/components/**/*.{ts,tsx,js}'], moduleNameMapper: { '\\.(css|less)$': '/__tests__/styleMock.js', 'react-syntax-highlighter/dist/esm/light': From 58041ddd0928753cbbc04377c04c858bf14c69ce Mon Sep 17 00:00:00 2001 From: Anastasia Lanz Date: Sat, 3 Feb 2024 16:21:59 -0600 Subject: [PATCH 2/5] chore: don't check .ts files for coverage --- packages/react/jest.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/jest.config.ts b/packages/react/jest.config.ts index 0668bc568..b086afbfe 100644 --- a/packages/react/jest.config.ts +++ b/packages/react/jest.config.ts @@ -8,7 +8,7 @@ const config: Config = { '**/__tests__/demo/**/*.js', '**/src/components/**/*.test.tsx' ], - collectCoverageFrom: ['/src/components/**/*.{ts,tsx,js}'], + collectCoverageFrom: ['/src/components/**/*.{tsx,js}'], moduleNameMapper: { '\\.(css|less)$': '/__tests__/styleMock.js', 'react-syntax-highlighter/dist/esm/light': From 185cb24d3e0b8d76e8994bff0733ccedcc10fcc1 Mon Sep 17 00:00:00 2001 From: Anastasia Lanz Date: Sat, 3 Feb 2024 20:16:50 -0600 Subject: [PATCH 3/5] test: convert tag tests to rtl --- .../react/src/components/Tag/index.test.tsx | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/react/src/components/Tag/index.test.tsx diff --git a/packages/react/src/components/Tag/index.test.tsx b/packages/react/src/components/Tag/index.test.tsx new file mode 100644 index 000000000..c65ab1bc7 --- /dev/null +++ b/packages/react/src/components/Tag/index.test.tsx @@ -0,0 +1,46 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import Tag, { TagLabel } from '../../../src/components/Tag'; +import axe from '../../axe'; + +test('renders children', () => { + render( + + Label: value + + ); + expect(screen.getByText('Label:')).toBeInTheDocument(); +}); + +test('passes classNames through', () => { + render( + + Tag: + hi + + ); + expect(screen.getByText('hi')).toHaveClass('baz'); + expect(screen.getByText('Tag:')).toHaveClass('jazz'); +}); + +test('passes arbitrary props through', () => { + render( + + hi + bye + + ); + expect(screen.getByText('bye')).toHaveAttribute('data-foo', 'true'); + expect(screen.getByText('hi')).toHaveAttribute('data-bar', 'yes'); +}); + +test('should return no axe violations', async () => { + const { container } = render( + + Label: value + + ); + + const results = await axe(container); + expect(results).toHaveNoViolations(); +}); From 0cbaec01301ae1a8867ca5d2edbddad209a47b99 Mon Sep 17 00:00:00 2001 From: Anastasia Lanz Date: Sat, 3 Feb 2024 20:25:21 -0600 Subject: [PATCH 4/5] test: remove old tag test --- .../__tests__/src/components/Tag/index.js | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 packages/react/__tests__/src/components/Tag/index.js diff --git a/packages/react/__tests__/src/components/Tag/index.js b/packages/react/__tests__/src/components/Tag/index.js deleted file mode 100644 index a2c344979..000000000 --- a/packages/react/__tests__/src/components/Tag/index.js +++ /dev/null @@ -1,37 +0,0 @@ -import React from 'react'; -import { shallow, mount } from 'enzyme'; -import Tag, { TagLabel } from '../../../../src/components/Tag'; -import axe from '../../../axe'; - -test('renders children', () => { - const tag = mount( - - Label: value - - ); - - expect(tag.text()).toBe('Label: value'); -}); - -test('passes classNames through', () => { - const tag = shallow(hi); - const tagLabel = shallow(hi); - expect(tag.is('.baz')).toBe(true); - expect(tagLabel.is('.jazz')).toBe(true); -}); - -test('passes arbitrary props through', () => { - const tag = shallow(bye); - const tagLabel = shallow(hi); - expect(tag.is('[data-foo="true"]')).toBe(true); - expect(tagLabel.is('[data-bar="yes"]')).toBe(true); -}); - -test('should return no axe violations', async () => { - const tag = shallow( - - Label: value - - ); - expect(await axe(tag.html())).toHaveNoViolations(); -}); From 6b2c6480610713a4e39b43dfac7b67f5c6c66bd9 Mon Sep 17 00:00:00 2001 From: Anastasia Lanz Date: Mon, 5 Feb 2024 11:26:55 -0600 Subject: [PATCH 5/5] Update packages/react/jest.config.ts Co-authored-by: Jason --- packages/react/jest.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/jest.config.ts b/packages/react/jest.config.ts index b086afbfe..dfcd3d335 100644 --- a/packages/react/jest.config.ts +++ b/packages/react/jest.config.ts @@ -8,7 +8,7 @@ const config: Config = { '**/__tests__/demo/**/*.js', '**/src/components/**/*.test.tsx' ], - collectCoverageFrom: ['/src/components/**/*.{tsx,js}'], + collectCoverageFrom: ['/src/components/**/*.{tsx,ts}'], moduleNameMapper: { '\\.(css|less)$': '/__tests__/styleMock.js', 'react-syntax-highlighter/dist/esm/light':