File size: 1,432 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
 * Testing our link component
 */

import React from 'react';
import { render } from 'react-testing-library';

import A from '../index';

const href = 'http://mxstbr.com/';
const children = <h1>Test</h1>;
const renderComponent = (props = {}) =>
  render(
    <A href={href} {...props}>
      {children}
    </A>,
  );

describe('<A />', () => {
  it('should render an <a> tag', () => {
    const { container } = renderComponent();
    expect(container.querySelector('a')).not.toBeNull();
  });

  it('should have an href attribute', () => {
    const { container } = renderComponent();
    expect(container.querySelector('a').href).toEqual(href);
  });

  it('should have children', () => {
    const { container } = renderComponent();
    expect(container.querySelector('a').children).toHaveLength(1);
  });

  it('should have a class attribute', () => {
    const className = 'test';
    const { container } = renderComponent({ className });
    expect(container.querySelector('a').classList).toContain(className);
  });

  it('should adopt a target attribute', () => {
    const target = '_blank';
    const { container } = renderComponent({ target });
    expect(container.querySelector('a').target).toEqual(target);
  });

  it('should adopt a type attribute', () => {
    const type = 'text/html';
    const { container } = renderComponent({ type });
    expect(container.querySelector('a').type).toEqual(type);
  });
});