import assert from 'assert';
import SpiesTeardown from './spies-teardown';
import ReactTester from '../../../src/index';

describe('spies teardown', () => {
  let component;

  beforeEach(() => {
    component = ReactTester
      .create()
      .use(SpiesTeardown);
  });

  describe('refreshes spies each time', () => {
    beforeEach(() => {
      component
        .addFlavour('lemon', {});
    });

    it('is called once the first time I check', () => {
      const callcount = component.ComponentToUse.prototype.spiedOn.callCount;

      assert(callcount, 1);
    });

    it('is called once the second time I check', () => {
      const callcount = component.ComponentToUse.prototype.spiedOn.callCount;

      assert(callcount, 1);
    });
  });

  describe('allows me to tear down when I want to', () => {
    beforeEach(() => {
      component
        .addFlavour('chocolate', {});
    });

    it('spies automatically', () => {
      const isSpy = component.ComponentToUse.prototype.spiedOn.isSinonProxy;

      assert(isSpy, true);
    });

    it('can be unwrapped', () => {
      component.teardown();
      const isSpy = typeof component.ComponentToUse.prototype.spiedOn.isSinonProxy;

      assert(isSpy, 'undefined');
    });
  });
});

import assert from 'assert';
import SpiesTeardown from './spies-teardown';
import ReactTester from '../../../src/index';

describe('spies teardown', () => {
  let tester;

  beforeEach(() => {
    tester = ReactTester
      .create()
      .use(SpiesTeardown);
  });

  describe('refresh spies each time should', () => {
    beforeEach(() => tester.addFlavour('LEMON', {}));

    it('allow normal spy behaviour on the first test pass', () => {
      const actual = tester.ComponentToUse.prototype.spiedOn.callCount;
      const expected = 1;

      assert(actual, expected);
    });

    it('allow normal spy behaviour on the second test pass', () => {
      const actual = tester.ComponentToUse.prototype.spiedOn.callCount;
      const expected = 1;

      assert(actual, expected);
    });
  });

  describe('should', () => {
    beforeEach(() => tester.addFlavour('CHOCOLATE', {}));

    it('add spies automatically', () => {
      const actual = tester.ComponentToUse.prototype.spiedOn.isSinonProxy;
      const expected = true;
      assert(actual, expected);
    });

    it('allow them to be unwrapped', () => {
      tester.teardown();
      const actual = typeof tester.ComponentToUse.prototype.spiedOn.isSinonProxy;
      const expected = 'undefined';

      assert(actual, expected);
    });
  });
});

Bring tests inline with CraigB style
Bring tests inline with CraigB style
