Skip to content

Remove all remaining .snap snapshot tests from React components #6380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/react/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = {
'<rootDir>/src/Breadcrumbs/',
'<rootDir>/src/ButtonGroup/',
'<rootDir>/src/CheckboxGroup/',
'<rootDir>/src/CircleBadge/',
'<rootDir>/src/CircleOcticon/',
'<rootDir>/src/DataTable/',
'<rootDir>/src/Dialog/',
Expand Down Expand Up @@ -57,7 +56,6 @@ module.exports = {
'<rootDir>/src/Spinner/',
'<rootDir>/src/SplitPageLayout/',
'<rootDir>/src/Stack/',
'<rootDir>/src/StateLabel/',
'<rootDir>/src/SubNav/',
'<rootDir>/src/TabNav/',
'<rootDir>/src/TextInputWithTokens/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('AnchoredOverlay', () => {

it('should render consistently when open', () => {
const {container} = render(<AnchoredOverlayTestComponent initiallyOpen={true} />)
expect(container).toMatchSnapshot()
expect(container.firstChild).toBeInTheDocument()
})

it('should call onPositionChange when provided', async () => {
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion packages/react/src/AvatarStack/AvatarStack.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('AvatarStack', () => {

it('respects alignRight props', () => {
const {container} = render(rightAvatarComp)
expect(container.firstChild).toMatchSnapshot()
expect(container.firstChild).toBeInTheDocument()
expect(container.firstChild).toHaveAttribute('data-align-right', 'true')
})

it('should have a tabindex of 0 if there are no interactive children', () => {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {render as HTMLRender} from '@testing-library/react'
import Breadcrumbs from '../'
import {describe, expect, it} from 'vitest'
import {describe, expect, it} from '@jest/globals'

describe('Breadcrumbs.Item', () => {
it('renders an <a> by default', () => {
Expand All @@ -9,7 +9,9 @@ describe('Breadcrumbs.Item', () => {
})

it('respects the "selected" prop', () => {
const {container} = HTMLRender(<Breadcrumbs.Item selected />)
expect(container.firstChild).toMatchSnapshot()
const {getByRole} = HTMLRender(<Breadcrumbs.Item selected />)
const item = getByRole('link')
expect(item).toHaveAttribute('aria-current', 'page')
expect(item).toHaveClass('selected')
})
})

This file was deleted.

24 changes: 16 additions & 8 deletions packages/react/src/Button/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ describe('Button', () => {
</Button>,
)
const button = container.getByRole('button')
expect(button).toMatchSnapshot()
// Check that block styling is applied
expect(button).toHaveAttribute('data-block', 'block')
})

it('respects the "disabled" prop', () => {
Expand All @@ -99,17 +100,19 @@ describe('Button', () => {
</Button>,
)
const button = container.getByRole('button')
expect(button).toMatchSnapshot()
// Check that small size styling is applied
expect(button).toHaveAttribute('data-size', 'small')
})

it('respects the large size prop', () => {
const container = render(
<Button size="large" id="test-button">
Smol
Large
</Button>,
)
const button = container.getByRole('button')
expect(button).toMatchSnapshot()
// Check that large size styling is applied
expect(button).toHaveAttribute('data-size', 'large')
})

it('styles primary button appropriately', () => {
Expand All @@ -119,7 +122,8 @@ describe('Button', () => {
</Button>,
)
const button = container.getByRole('button')
expect(button).toMatchSnapshot()
// Check that primary variant styling is applied
expect(button).toHaveAttribute('data-variant', 'primary')
})

it('styles invisible button appropriately', () => {
Expand All @@ -129,7 +133,8 @@ describe('Button', () => {
</Button>,
)
const button = container.getByRole('button')
expect(button).toMatchSnapshot()
// Check that invisible variant styling is applied
expect(button).toHaveAttribute('data-variant', 'invisible')
})

it('styles danger button appropriately', () => {
Expand All @@ -139,7 +144,8 @@ describe('Button', () => {
</Button>,
)
const button = container.getByRole('button')
expect(button).toMatchSnapshot()
// Check that danger variant styling is applied
expect(button).toHaveAttribute('data-variant', 'danger')
})

it('makes sure icon button has an aria-label', () => {
Expand All @@ -155,7 +161,9 @@ describe('Button', () => {
</Button>,
)
const button = container.getByRole('button')
expect(button).toMatchSnapshot()
// Check that alignContent styling is applied - it's on the inner buttonContent element
const buttonContent = button.querySelector('[data-component="buttonContent"]')
expect(buttonContent).toHaveAttribute('data-align', 'start')
})

it('should render the leadingVisual prop before the button content', () => {
Expand Down
Loading
Loading