Skip to content

Commit 6f76705

Browse files
authored
test(Badge): migrate to rtl (react-bootstrap#6201)
1 parent 5fc649e commit 6f76705

File tree

2 files changed

+60
-38
lines changed

2 files changed

+60
-38
lines changed

test/BadgeSpec.js

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

test/BadgeSpec.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { render } from '@testing-library/react';
2+
3+
import Badge from '../src/Badge';
4+
5+
describe('Badge', () => {
6+
it('Should render correctly', () => {
7+
const { getByTestId } = render(
8+
<Badge bg="primary" pill data-testid="test">
9+
Message
10+
</Badge>,
11+
);
12+
13+
const badge = getByTestId('test');
14+
badge.innerText.should.equal('Message');
15+
badge.classList.contains('badge').should.be.true;
16+
badge.classList.contains('bg-primary').should.be.true;
17+
badge.classList.contains('rounded-pill').should.be.true;
18+
});
19+
20+
it('should support custom `as`', () => {
21+
const { getByTestId } = render(
22+
<Badge as="a" href="#" bg="primary" pill data-testid="test">
23+
Message
24+
</Badge>,
25+
);
26+
27+
const badge = getByTestId('test');
28+
badge.tagName.toLowerCase().should.equal('a');
29+
badge.getAttribute('href').should.equal('#');
30+
});
31+
32+
it('Should default to bg="primary"', () => {
33+
const { getByTestId } = render(<Badge data-testid="test">Message</Badge>);
34+
35+
const badge = getByTestId('test');
36+
badge.classList.contains('bg-primary').should.be.true;
37+
});
38+
39+
it('Should use bg class', () => {
40+
const { getByTestId } = render(
41+
<Badge bg="danger" data-testid="test">
42+
Message
43+
</Badge>,
44+
);
45+
46+
const badge = getByTestId('test');
47+
badge.classList.contains('bg-danger').should.be.true;
48+
});
49+
50+
it('Should not have bg class when bg=null', () => {
51+
const { getByTestId } = render(
52+
<Badge bg={null} data-testid="test">
53+
Message
54+
</Badge>,
55+
);
56+
57+
const badge = getByTestId('test');
58+
badge.classList.contains('bg-primary').should.be.false;
59+
});
60+
});

0 commit comments

Comments
 (0)