Skip to content

Commit

Permalink
Limit jest.spy to console.warn specific tests and change changeset de…
Browse files Browse the repository at this point in the history
…scription
  • Loading branch information
kendallgassner committed Jan 24, 2025
1 parent 55951e0 commit b3b2235
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .changeset/orange-roses-give.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@primer/react": minor
---

Changed ProgressBar.Item to require an aria-label.
In dev mode, warn users to add an aria-label to ProgressBar.Item if the ProgressBar.Item is not aria-hidden.
44 changes: 23 additions & 21 deletions packages/react/src/__tests__/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ import axe from 'axe-core'
import {FeatureFlags} from '../FeatureFlags'

describe('ProgressBar', () => {
const mockWarningFn = jest.fn()

beforeEach(() => {
jest.spyOn(global.console, 'warn').mockImplementation(mockWarningFn)
})

afterEach(() => {
jest.clearAllMocks()
})

behavesAsComponent({
Component: ProgressBar,
toRender: () => <ProgressBar aria-label="Upload test.png" aria-valuenow={10} progress={0} />,
Expand Down Expand Up @@ -123,18 +113,30 @@ describe('ProgressBar', () => {
expect(getByRole('progressbar')).toHaveAttribute('aria-valuenow', '0')
})

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

it('should not warn users if aria-label is not provided but aria-hidden is', () => {
HTMLRender(<ProgressBar.Item progress={50} aria-hidden={true} />)
expect(mockWarningFn).not.toHaveBeenCalled()
})
beforeEach(() => {
jest.spyOn(global.console, 'warn').mockImplementation(mockWarningFn)
})

afterEach(() => {
jest.clearAllMocks()
})

it('should warn users if aria-label is not provided', () => {
HTMLRender(<ProgressBar.Item progress={50} />)
expect(mockWarningFn).toHaveBeenCalled()
})

it('should not warn users if aria-label is not provided but aria-hidden is', () => {
HTMLRender(<ProgressBar.Item progress={50} aria-hidden={true} />)
expect(mockWarningFn).not.toHaveBeenCalled()
})

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

0 comments on commit b3b2235

Please sign in to comment.