Skip to content

Commit b3b2235

Browse files
Limit jest.spy to console.warn specific tests and change changeset description
1 parent 55951e0 commit b3b2235

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

.changeset/orange-roses-give.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@primer/react": minor
33
---
44

5-
Changed ProgressBar.Item to require an aria-label.
5+
In dev mode, warn users to add an aria-label to ProgressBar.Item if the ProgressBar.Item is not aria-hidden.

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

+23-21
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ import axe from 'axe-core'
66
import {FeatureFlags} from '../FeatureFlags'
77

88
describe('ProgressBar', () => {
9-
const mockWarningFn = jest.fn()
10-
11-
beforeEach(() => {
12-
jest.spyOn(global.console, 'warn').mockImplementation(mockWarningFn)
13-
})
14-
15-
afterEach(() => {
16-
jest.clearAllMocks()
17-
})
18-
199
behavesAsComponent({
2010
Component: ProgressBar,
2111
toRender: () => <ProgressBar aria-label="Upload test.png" aria-valuenow={10} progress={0} />,
@@ -123,18 +113,30 @@ describe('ProgressBar', () => {
123113
expect(getByRole('progressbar')).toHaveAttribute('aria-valuenow', '0')
124114
})
125115

126-
it('should warn users if aria-label is not provided', () => {
127-
HTMLRender(<ProgressBar.Item progress={50} />)
128-
expect(mockWarningFn).toHaveBeenCalled()
129-
})
116+
describe('console.warn', () => {
117+
const mockWarningFn = jest.fn()
130118

131-
it('should not warn users if aria-label is not provided but aria-hidden is', () => {
132-
HTMLRender(<ProgressBar.Item progress={50} aria-hidden={true} />)
133-
expect(mockWarningFn).not.toHaveBeenCalled()
134-
})
119+
beforeEach(() => {
120+
jest.spyOn(global.console, 'warn').mockImplementation(mockWarningFn)
121+
})
122+
123+
afterEach(() => {
124+
jest.clearAllMocks()
125+
})
126+
127+
it('should warn users if aria-label is not provided', () => {
128+
HTMLRender(<ProgressBar.Item progress={50} />)
129+
expect(mockWarningFn).toHaveBeenCalled()
130+
})
131+
132+
it('should not warn users if aria-label is not provided but aria-hidden is', () => {
133+
HTMLRender(<ProgressBar.Item progress={50} aria-hidden={true} />)
134+
expect(mockWarningFn).not.toHaveBeenCalled()
135+
})
135136

136-
it('should not warn users if aria-label is provided', () => {
137-
HTMLRender(<ProgressBar.Item progress={50} aria-label="Uploading test.png" />)
138-
expect(mockWarningFn).not.toHaveBeenCalled()
137+
it('should not warn users if aria-label is provided', () => {
138+
HTMLRender(<ProgressBar.Item progress={50} aria-label="Uploading test.png" />)
139+
expect(mockWarningFn).not.toHaveBeenCalled()
140+
})
139141
})
140142
})

0 commit comments

Comments
 (0)