Skip to content

Commit edbb7b9

Browse files
authored
refactor: update tests to vitest (#6031)
1 parent 6c7ee70 commit edbb7b9

File tree

16 files changed

+21015
-12570
lines changed

16 files changed

+21015
-12570
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react/jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ module.exports = {
3434
'<rootDir>/src/Banner/',
3535
'<rootDir>/src/DataTable/',
3636
'<rootDir>/src/FeatureFlags/',
37+
'<rootDir>/src/Select/',
38+
'<rootDir>/src/Skeleton/',
39+
'<rootDir>/src/Spinner/',
3740
'<rootDir>/src/Stack/',
41+
'<rootDir>/src/StateLabel/',
42+
'<rootDir>/src/SubNav/',
43+
'<rootDir>/src/TabNav/',
44+
'<rootDir>/src/TextInputWithTokens/',
45+
'<rootDir>/src/Timeline/',
3846
'<rootDir>/src/ToggleSwitch/',
47+
'<rootDir>/src/Tooltip/',
48+
'<rootDir>/src/TooltipV2/',
3949
'<rootDir>/src/Truncate/',
4050
'<rootDir>/src/UnderlineNav/',
4151
],

packages/react/src/Select/Select.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import {describe, expect, it} from 'vitest'
23
import {Select} from '..'
34
import {render} from '@testing-library/react'
45
import userEvent from '@testing-library/user-event'

packages/react/src/Skeleton/__tests__/SkeletonBox.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {render} from '@testing-library/react'
22
import React from 'react'
3+
import {describe, expect, it} from 'vitest'
34
import {SkeletonBox} from '../SkeletonBox'
45

56
describe('SkeletonBox', () => {

packages/react/src/Spinner/Spinner.test.tsx

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,41 @@
11
import React from 'react'
2-
import axe from 'axe-core'
32
import type {SpinnerProps} from '..'
43
import {Spinner} from '..'
5-
import {behavesAsComponent, checkExports} from '../utils/testing'
6-
import {render as HTMLRender, screen} from '@testing-library/react'
4+
import {render, screen} from '@testing-library/react'
5+
import {describe, expect, it} from 'vitest'
76

87
describe('Spinner', () => {
9-
behavesAsComponent({
10-
Component: Spinner,
11-
options: {
12-
skipAs: true,
13-
},
14-
})
15-
16-
checkExports('Spinner', {
17-
default: Spinner,
18-
})
19-
208
it('should support `className` on the outermost element', () => {
219
const Element = () => <Spinner className={'test-class-name'} />
22-
expect(HTMLRender(<Element />).container.firstChild?.firstChild).toHaveClass('test-class-name')
10+
expect(render(<Element />).container.firstChild?.firstChild).toHaveClass('test-class-name')
2311
})
2412

2513
it('should label the spinner with default loading text', async () => {
26-
const {getByLabelText} = HTMLRender(<Spinner />)
14+
const {getByLabelText} = render(<Spinner />)
2715

2816
expect(getByLabelText('Loading')).toBeInTheDocument()
2917
})
3018

3119
it('should label the spinner with with custom loading text', async () => {
32-
const {getByLabelText} = HTMLRender(<Spinner srText="Custom loading text" />)
20+
const {getByLabelText} = render(<Spinner srText="Custom loading text" />)
3321

3422
expect(getByLabelText('Custom loading text')).toBeInTheDocument()
3523
})
3624

3725
it('should not label the spinner with with loading text when `srText` is set to `null`', () => {
38-
const {getByLabelText} = HTMLRender(<Spinner srText={null} />)
26+
const {getByLabelText} = render(<Spinner srText={null} />)
3927

4028
expect(() => getByLabelText('Loading')).toThrow()
4129
})
4230

4331
it('should use `aria-label` over `srText` if `aria-label` is provided', () => {
44-
HTMLRender(<Spinner aria-label="Test label" />)
32+
render(<Spinner aria-label="Test label" />)
4533
expect(screen.getByLabelText('Test label')).toBeInTheDocument()
4634
})
4735

48-
it('should have no axe violations', async () => {
49-
const {container} = HTMLRender(<Spinner />)
50-
const results = await axe.run(container)
51-
expect(results).toHaveNoViolations()
52-
})
53-
5436
it('should respect size arguments', () => {
5537
const expectSize = (input: SpinnerProps['size'] | undefined, expectedSize: string) => {
56-
const {container} = HTMLRender(<Spinner size={input} />)
38+
const {container} = render(<Spinner size={input} />)
5739
const svg = container.querySelector('svg')!
5840
expect(svg.getAttribute('height')).toEqual(expectedSize)
5941
expect(svg.getAttribute('width')).toEqual(expectedSize)

packages/react/src/StateLabel/__tests__/StateLabel.test.tsx

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,24 @@
11
import React from 'react'
2+
import {describe, expect, it} from 'vitest'
23
import StateLabel from '../StateLabel'
3-
import {render, behavesAsComponent, checkExports} from '../../utils/testing'
44
import {render as HTMLRender} from '@testing-library/react'
5-
import axe from 'axe-core'
65

76
describe('StateLabel', () => {
8-
behavesAsComponent({
9-
Component: StateLabel,
10-
toRender: () => <StateLabel status="issueOpened">Open</StateLabel>,
11-
options: {
12-
// Rendering a Octicon seems to break getComputedStyles, which
13-
// the sx prop implementation test uses to make sure the prop is working correctly.
14-
// Despite my best efforts, I cannot figure out why this is happening. So,
15-
// unfortunately, we will simply skip this test.
16-
skipSx: true,
17-
},
18-
})
19-
20-
checkExports('StateLabel', {
21-
default: StateLabel,
22-
})
23-
24-
it('should have no axe violations', async () => {
25-
const {container} = HTMLRender(<StateLabel status="issueOpened" />)
26-
const results = await axe.run(container)
27-
expect(results).toHaveNoViolations()
28-
})
29-
307
it('respects the status prop', () => {
31-
expect(render(<StateLabel status="issueOpened" />)).toMatchSnapshot()
32-
expect(render(<StateLabel status="issueClosed" />)).toMatchSnapshot()
33-
expect(render(<StateLabel status="issueClosedNotPlanned" />)).toMatchSnapshot()
34-
expect(render(<StateLabel status="pullMerged" />)).toMatchSnapshot()
35-
expect(render(<StateLabel status="pullQueued" />)).toMatchSnapshot()
8+
expect(HTMLRender(<StateLabel status="issueOpened" />).container).toMatchSnapshot()
9+
expect(HTMLRender(<StateLabel status="issueClosed" />).container).toMatchSnapshot()
10+
expect(HTMLRender(<StateLabel status="issueClosedNotPlanned" />).container).toMatchSnapshot()
11+
expect(HTMLRender(<StateLabel status="pullMerged" />).container).toMatchSnapshot()
12+
expect(HTMLRender(<StateLabel status="pullQueued" />).container).toMatchSnapshot()
3613
})
3714

3815
it('respects the variant prop', () => {
39-
expect(render(<StateLabel variant="small" status="issueOpened" />)).toMatchSnapshot()
40-
expect(render(<StateLabel variant="normal" status="issueOpened" />)).toMatchSnapshot()
16+
expect(HTMLRender(<StateLabel variant="small" status="issueOpened" />).container).toMatchSnapshot()
17+
expect(HTMLRender(<StateLabel variant="normal" status="issueOpened" />).container).toMatchSnapshot()
4118
})
4219

4320
it('renders children', () => {
44-
expect(render(<StateLabel status="issueOpened">hi</StateLabel>)).toMatchSnapshot()
21+
expect(HTMLRender(<StateLabel status="issueOpened">hi</StateLabel>).container).toMatchSnapshot()
4522
})
4623

4724
it('adds label to icon', () => {

0 commit comments

Comments
 (0)