Skip to content

Commit

Permalink
Adding className tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrohan committed Nov 1, 2024
1 parent fc834b6 commit d68a084
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/react/src/Stack/__tests__/Stack.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import {render, screen} from '@testing-library/react'
import React from 'react'
import {Stack} from '../Stack'
import {FeatureFlags} from '../../FeatureFlags'

describe('Stack', () => {
it('should support `className` on the outermost element', () => {
const Element = () => <Stack className={'test-class-name'} />
const FeatureFlagElement = () => {
return (
<FeatureFlags
flags={{
primer_react_css_modules_team: true,
primer_react_css_modules_staff: true,
primer_react_css_modules_ga: true,
}}
>
<Element />
</FeatureFlags>
)
}
expect(render(<Element />).container.firstChild).toHaveClass('test-class-name')
expect(render(<FeatureFlagElement />).container.firstChild).toHaveClass('test-class-name')
})

it('should support rendering content through `children`', () => {
render(
<Stack>
Expand Down
26 changes: 26 additions & 0 deletions packages/react/src/Stack/__tests__/StackItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
import {render, screen} from '@testing-library/react'
import React from 'react'
import {Stack, StackItem} from '../Stack'
import {FeatureFlags} from '../../FeatureFlags'

describe('StackItem', () => {
it('should support `className` on the outermost element', () => {
const Element = () => (
<Stack>
<StackItem data-testid="stack-item" className={'test-class-name'}>
Content
</StackItem>
</Stack>
)
const FeatureFlagElement = () => {
return (
<FeatureFlags
flags={{
primer_react_css_modules_team: true,
primer_react_css_modules_staff: true,
primer_react_css_modules_ga: true,
}}
>
<Element />
</FeatureFlags>
)
}
expect(render(<Element />).getAllByTestId('stack-item')[0]).toHaveClass('test-class-name')
expect(render(<FeatureFlagElement />).getAllByTestId('stack-item')[1]).toHaveClass('test-class-name')
})

it('should render its children', () => {
render(
<Stack>
Expand Down

0 comments on commit d68a084

Please sign in to comment.