{"size": 2409, "ext": "js", "max_stars_repo_path": "client/src/components/delayedRender/delayedRender.spec.js", "max_stars_repo_name": "jejdacz/evidence", "max_stars_repo_stars_event_min_datetime": "2019-04-22T13:37:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-01T13:38:30.000Z", "max_issues_repo_path": "client/src/components/delayedRender/delayedRender.spec.js", "max_issues_repo_name": "jejdacz/evidence", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/components/delayedRender/delayedRender.spec.js", "max_forks_repo_name": "jejdacz/evidence", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.011627907, "max_line_length": 75, "alphanum_fraction": 0.5230386052}
import React from "react";
import { mount } from "enzyme";
import delayedRender from "./delayedRender";

const Base = props => <div />;
const delay = 100;
const Sample = delayedRender(delay)(Base);

describe("component decorated with withDelayedRender", () => {
  let wrapper;
  beforeEach(() => {
    wrapper = mount(<Sample />);
  });

  it("should have prop shouldRender set to default (true)", () => {
    expect(wrapper).toHaveProp("shouldRender", true);
  });

  describe("when shouldRender is true", () => {
    it("should render nothing first", () => {
      expect(wrapper.html()).toBeNull();
    });

    it("should render nothing before delay", done => {
      setTimeout(() => {
        expect(wrapper.html()).toBeNull();
        done();
      }, delay - 50);
    });

    it("should render content after delay", done => {
      setTimeout(() => {
        expect(wrapper.html()).not.toBeNull();
        done();
      }, delay + 50);
    });

    describe("when shouldRender changes to false within delay", () => {
      it("should render nothing", done => {
        setTimeout(() => {
          wrapper.setProps({ shouldRender: false });
          expect(wrapper.html()).toBeNull();
          done();
        }, delay - 50);
      });

      describe("when shouldRender changes to false after delay", () => {
        it("should render nothing", done => {
          setTimeout(() => {
            wrapper.setProps({ shouldRender: false });
            expect(wrapper.html()).toBeNull();
            done();
          }, delay + 50);
        });
      });
    });

    describe("when shouldRender is false", () => {
      it("should render nothing first", () => {
        expect(mount(<Sample shouldRender={false} />)).toBeEmptyRender();
      });

      it("should render nothing after delay", done => {
        setTimeout(() => {
          expect(mount(<Sample shouldRender={false} />)).toBeEmptyRender();
          done();
        }, delay + 50);
      });

      describe("when shouldRender changes to true", () => {
        it("should render content after delay", done => {
          setTimeout(() => {
            wrapper.setProps({ shouldRender: true });
            expect(wrapper.html()).toBeNull();
          }, 50);

          setTimeout(() => {
            expect(wrapper.html()).not.toBeNull();
            done();
          }, 50 + delay + 50);
        });
      });
    });
  });
});
