Skip to content

Commit 32dfb41

Browse files
authored
test: move Image to RTL (react-bootstrap#6222)
* Delete AlertSpec.js * add AlertSpec.tsx * Delete ImageSpec.js * Create ImageSpec.tsx
1 parent 76d0737 commit 32dfb41

File tree

2 files changed

+55
-35
lines changed

2 files changed

+55
-35
lines changed

test/ImageSpec.js

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

test/ImageSpec.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { render } from '@testing-library/react';
2+
3+
import Image from '../src/Image';
4+
5+
describe('Image', () => {
6+
it('should be an image', () => {
7+
8+
const { getByTestId } = render(
9+
<Image data-testid="test-image" />,
10+
);
11+
getByTestId('test-image').tagName.toLowerCase().should.equal('img');
12+
});
13+
14+
it('should provide src and alt prop', () => {
15+
const { getByTestId } = render(
16+
<Image data-testid="test-image" src="image.jpg" alt="this is alt" />,
17+
);
18+
getByTestId('test-image').getAttribute('src')!.should.equal('image.jpg');
19+
getByTestId('test-image').getAttribute('alt')!.should.equal('this is alt');
20+
21+
});
22+
23+
it('should have correct class when fluid prop is set', () => {
24+
const { getByTestId } = render(<Image data-testid="test-image" fluid />);
25+
getByTestId('test-image').classList.contains('img-fluid').should.be.true;
26+
});
27+
28+
it('should not override class when rounded prop is set', () => {
29+
const { getByTestId } = render(
30+
<Image data-testid="test-image" fluid rounded />,
31+
);
32+
getByTestId('test-image').classList.contains('img-fluid').should.be.true;
33+
getByTestId('test-image').classList.contains('rounded').should.be.true;
34+
35+
});
36+
37+
it('should have correct class when rounded prop is set', () => {
38+
const { getByTestId } = render(<Image data-testid="test-image" rounded />);
39+
getByTestId('test-image').classList.contains('rounded').should.be.true;
40+
});
41+
42+
it('should have correct class when roundedCircle prop is set', () => {
43+
const { getByTestId } = render(
44+
<Image data-testid="test-image" roundedCircle />,
45+
);
46+
getByTestId('test-image').classList.contains('rounded-circle').should.be.true;
47+
48+
});
49+
50+
it('should have correct class when thumbnail prop is set', () => {
51+
const { getByTestId } = render(<Image data-testid="test-image" thumbnail />);
52+
getByTestId('test-image').classList.contains('img-thumbnail').should.be.true;
53+
54+
});
55+
});

0 commit comments

Comments
 (0)