MetaPhase-Consulting/State-TalentMAP

View on GitHub
src/Components/Form/Form.test.jsx

Summary

Maintainability
A
0 mins
Test Coverage
import { shallow } from 'enzyme';
import toJSON from 'enzyme-to-json';
import sinon from 'sinon';
import Form from './Form';

describe('FormComponent', () => {
  it('is defined', () => {
    const wrapper = shallow(
      <Form onFormSubmit={() => {}}>
        <span>child</span>
      </Form>,
    );
    expect(wrapper).toBeDefined();
  });

  it('accepts a className', () => {
    const className = 'test-class';
    const wrapper = shallow(
      <Form onFormSubmit={() => {}} className={className}>
        <span>child</span>
      </Form>,
    );
    expect(wrapper.find(`.${className}`)).toBeDefined();
  });

  it('calls onFormSubmit', () => {
    const spy = sinon.spy();
    const wrapper = shallow(
      <Form onFormSubmit={spy}>
        <span>child</span>
      </Form>,
    );
    wrapper.find('form').props().onSubmit();
    sinon.assert.calledOnce(spy);
  });

  it('matches snapshot', () => {
    const wrapper = shallow(
      <Form onFormSubmit={() => {}}>
        <span>child</span>
      </Form>,
    );
    expect(toJSON(wrapper)).toMatchSnapshot();
  });
});