-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathAvatar.test.jsx
41 lines (37 loc) · 1.29 KB
/
Avatar.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from 'react';
import renderer from 'react-test-renderer';
import Avatar from './index';
describe('Avatar', () => {
it('renders in all sizes', () => {
const tree = renderer.create((
<>
<Avatar size="xs" />
<Avatar size="sm" />
<Avatar />
<Avatar size="lg" />
<Avatar size="xl" />
<Avatar size="xxl" />
<Avatar size="huge" />
</>
)).toJSON();
expect(tree).toMatchSnapshot();
});
it('has a default avatar url', () => {
const testRenderer = renderer.create(<Avatar />);
const testInstance = testRenderer.root;
// test-file-stub is what our fileMock.js returns for all images and svgs
expect(testInstance.findByType('img').props.src).toBe('test-file-stub');
});
it('can set a custom avatar url', () => {
const profileUrl = 'https://example.com/profile.png';
const testRenderer = renderer.create(<Avatar src={profileUrl} />);
const testInstance = testRenderer.root;
expect(testInstance.findByType('img').props.src).toBe(profileUrl);
});
it('can have alt text', () => {
const altText = 'Casey';
const testRenderer = renderer.create(<Avatar alt={altText} />);
const testInstance = testRenderer.root;
expect(testInstance.findByType('img').props.alt).toBe(altText);
});
});