{"size": 1591, "ext": "js", "max_stars_repo_path": "packages/if/src/index.spec.js", "max_stars_repo_name": "daniloster/react-experiments", "max_stars_repo_stars_event_min_datetime": "2018-06-14T09:54:11.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-14T09:54:11.000Z", "max_issues_repo_path": "packages/if/src/index.spec.js", "max_issues_repo_name": "daniloster/react-experiments", "max_issues_repo_issues_event_min_datetime": "2017-08-30T23:45:03.000Z", "max_issues_repo_issues_event_max_datetime": "2017-09-13T18:53:47.000Z", "max_forks_repo_path": "packages/if/src/index.spec.js", "max_forks_repo_name": "daniloster/react-experiments", "max_forks_repo_forks_event_min_datetime": "2017-09-21T09:45:47.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-02T08:50:51.000Z"}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": 3, "avg_line_length": 26.5166666667, "max_line_length": 84, "alphanum_fraction": 0.5751099937}
import React from 'react';
import { mount } from 'enzyme';
import If from './index';

describe('<If/>', () => {
  let element;

  function mountComponent({ isValid = false, children = 'DANILOSTER IF' } = {}) {
    element = mount(
      <main>
        <If expression={isValid}>
          {children}
        </If>
      </main>
    );
  }

  function isTextPresent() {
    expect(element.text())
      .to.contain('DANILOSTER IF');
  }

  function isNotTextPresent() {
    expect(element.text())
      .to.not.contain('DANILOSTER IF');
  }

  describe('If should not display children', () => {
    it('Given the If has expression falsy', () => {
      mountComponent();
    });
    it('Expect the text to be not present', () => {
      isNotTextPresent();
    });
  });

  describe('If should display children wrapped by span when it is a string', () => {
    it('Given the If has expression truthy', () => {
      mountComponent({ isValid: true });
    });
    it('Expect the text to be present with wrapper', () => {
      isTextPresent();
      expect(element.find('span')).to.have.length(1);
      expect(element.find('div')).to.have.length(0);
    });
  });

  describe('If should display children with no wrap for components', () => {
    it('Given the If has expression truthy', () => {
      mountComponent({ isValid: true, children: <div>DANILOSTER IF</div> });
    });
    it('Expect the text to be present with no wrapper', () => {
      isTextPresent();
      expect(element.find('span')).to.have.length(0);
      expect(element.find('div')).to.have.length(1);
    });
  });

});
