File size: 1,143 Bytes
1e92f2d |
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 |
import React from 'react';
import { render } from 'react-testing-library';
import renderer from 'react-test-renderer';
import 'jest-styled-components';
import Img from '../Img';
describe('<Img />', () => {
it('should match the snapshot', () => {
const renderedComponent = renderer
.create(<Img src="http://example.com/test.jpg" alt="test" />)
.toJSON();
expect(renderedComponent).toMatchSnapshot();
});
it('should have a class attribute', () => {
const { container } = render(
<Img src="http://example.com/test.jpg" alt="test" />,
);
expect(container.querySelector('img').hasAttribute('class')).toBe(true);
});
it('should adopt a valid attribute', () => {
const { container } = render(
<Img src="http://example.com/test.jpg" alt="test" />,
);
expect(container.querySelector('img').alt).toEqual('test');
});
it('should not adopt an invalid attribute', () => {
const { container } = render(
<Img src="http://example.com/test.jpg" attribute="test" alt="test" />,
);
expect(container.querySelector('img').getAttribute('attribute')).toBeNull();
});
});
|