Skip to content

Commit 28df44e

Browse files
authored
test(CAlertHeading, CAlertLink): align to canonical cross-framework cases (#492)
Rewrite the alert subcomponent suites with behavior-named it() descriptions shared verbatim with Vue (render the element/class, render content, apply a custom class, and — for the heading — render as a custom element). Replaces snapshot-only coverage with explicit assertions.
1 parent f0a5534 commit 28df44e

4 files changed

Lines changed: 35 additions & 69 deletions

File tree

packages/coreui-react/src/components/alert/__tests__/CAlertHeading.spec.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import { render } from '@testing-library/react'
33
import '@testing-library/jest-dom'
44
import { CAlertHeading } from '../index'
55

6-
test('loads and displays CAlertHeading component', async () => {
7-
const { container } = render(<CAlertHeading>Test</CAlertHeading>)
8-
expect(container).toMatchSnapshot()
9-
})
6+
describe('CAlertHeading', () => {
7+
it('should render an alert heading', () => {
8+
const { container } = render(<CAlertHeading>Test</CAlertHeading>)
9+
expect(container.firstChild).toHaveClass('alert-heading')
10+
expect(container.firstChild?.nodeName).toBe('H4')
11+
})
12+
13+
it('should render its content', () => {
14+
const { getByText } = render(<CAlertHeading>Hello World!</CAlertHeading>)
15+
expect(getByText('Hello World!')).toBeInTheDocument()
16+
})
17+
18+
it('should apply a custom class name', () => {
19+
const { container } = render(<CAlertHeading className="bazinga">Test</CAlertHeading>)
20+
expect(container.firstChild).toHaveClass('bazinga')
21+
})
1022

11-
test('CAlertHeading customize', async () => {
12-
const { container } = render(
13-
<CAlertHeading as="h3" className="bazinga">
14-
Test
15-
</CAlertHeading>
16-
)
17-
expect(container).toMatchSnapshot()
18-
expect(container.firstChild).toHaveClass('bazinga')
19-
expect(container.firstChild).toHaveClass('alert-heading')
23+
it('should render as a custom element', () => {
24+
const { container } = render(<CAlertHeading as="h2">Test</CAlertHeading>)
25+
expect(container.firstChild?.nodeName).toBe('H2')
26+
})
2027
})

packages/coreui-react/src/components/alert/__tests__/CAlertLink.spec.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ import { render } from '@testing-library/react'
33
import '@testing-library/jest-dom'
44
import { CAlertLink } from '../index'
55

6-
test('loads and displays CAlertLink component', async () => {
7-
const { container } = render(<CAlertLink>Test</CAlertLink>)
8-
expect(container).toMatchSnapshot()
9-
})
6+
describe('CAlertLink', () => {
7+
it('should render an alert link', () => {
8+
const { container } = render(<CAlertLink>Test</CAlertLink>)
9+
expect(container.firstChild).toHaveClass('alert-link')
10+
expect(container.firstChild?.nodeName).toBe('A')
11+
})
12+
13+
it('should render its content', () => {
14+
const { getByText } = render(<CAlertLink>Hello World!</CAlertLink>)
15+
expect(getByText('Hello World!')).toBeInTheDocument()
16+
})
1017

11-
test('CAlertLink customize', async () => {
12-
const { container } = render(
13-
<CAlertLink className="bazinga" href="/bazinga">
14-
Test
15-
</CAlertLink>
16-
)
17-
expect(container).toMatchSnapshot()
18-
expect(container.firstChild).toHaveClass('bazinga')
19-
expect(container.firstChild).toHaveClass('alert-link')
18+
it('should apply a custom class name', () => {
19+
const { container } = render(<CAlertLink className="bazinga">Test</CAlertLink>)
20+
expect(container.firstChild).toHaveClass('bazinga')
21+
})
2022
})

packages/coreui-react/src/components/alert/__tests__/__snapshots__/CAlertHeading.spec.tsx.snap

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/coreui-react/src/components/alert/__tests__/__snapshots__/CAlertLink.spec.tsx.snap

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)