<commit_before>/* global describe, it */
import chai, { expect } from 'chai';
import React from 'react';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);

const sandbox = sinon.sandbox.create();
const createComponent = require('../src/createComponent');

describe('createComponent', function () {
  beforeEach(function () {
    sandbox.spy(React, 'createClass');
  });


  afterEach(function () {
    sandbox.restore();
  });

  it('creates a component', function () {
    const MyComponent = createComponent({
      myCustomFunction() { return 'foo'; },
      render() {
        return null;
      }
    });

    const myComponentInstance = new MyComponent();

    expect(React.createClass)
      .to.be.callCount(1)
      .and.to.be.calledWith({
        myCustomFunction: sinon.match.func,
        render: sinon.match.func,
        componentDidMount: sinon.match.func,
        componentWillUnmount: sinon.match.func
      });
    expect(myComponentInstance).to.be.instanceof(MyComponent);
    expect('isReactComponent' in Object.getPrototypeOf(myComponentInstance)).to.be.equal(true);
    expect(myComponentInstance.myCustomFunction()).to.be.equal('foo');
    expect(myComponentInstance.render()).to.be.equal(null);
  });
});<commit_msg>Reduced the 'boilerplate' code, although sandboxing for future additions is a proper way of doing.<commit_after>/* global describe, it */
import chai, { expect } from 'chai';
import React from 'react';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import createComponent from '../src/createComponent';

chai.use(sinonChai);
sinon.spy(React, 'createClass');


describe('createComponent', function () {
  it('creates a component', function () {
    const mySpec = {
      myCustomFunction() { return 'foo'; },
      render() {
        return null;
      }
    };
    const MyComponent = createComponent(mySpec);
    const myComponentInstance = new MyComponent();

    expect(React.createClass)
      .to.be.callCount(1)
      .and.to.be.calledWith({
        myCustomFunction: mySpec.myCustomFunction,
        render: mySpec.render,
        componentDidMount: sinon.match.func,
        componentWillUnmount: sinon.match.func
      });
    expect(myComponentInstance).to.be.instanceof(MyComponent);
    expect('isReactComponent' in Object.getPrototypeOf(myComponentInstance)).to.be.equal(true);
    expect(myComponentInstance.myCustomFunction()).to.be.equal('foo');
    expect(myComponentInstance.render()).to.be.equal(null);
  });
});
{'fraction_non_alphanumeric': 0.140761300555115, 'fraction_numerical': 0.0007930214115781126, 'mean_word_length': 3.76937618147448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2202397', 'n_tokens_mistral': 762, 'n_tokens_neox': 757, 'n_words': 149}