<commit_before>import React from 'react';
import { expect } from 'chai';
import omit from 'lodash/object/omit';
import { withState } from 'recompose';
import { BaseComponent } from './utils';

import {
  findRenderedComponentWithType,
  renderIntoDocument
} from 'react-addons-test-utils';

describe('withState()', () => {
  const Counter = withState('counter', 'updateCounter', 0)(BaseComponent);

  it('adds a stateful value and a function for updating it', () => {
    expect(Counter.displayName).to.equal(
      'withState(BaseComponent)'
    );

    const tree = renderIntoDocument(<Counter pass="through" />);
    const base = findRenderedComponentWithType(tree, BaseComponent);

    expect(omit(base.props, 'updateCounter')).to.eql({
      counter: 0,
      pass: 'through'
    });

    base.props.updateCounter(n => n + 9);
    base.props.updateCounter(n => n * 2);
    expect(omit(base.props, 'updateCounter')).to.eql({
      counter: 18,
      pass: 'through'
    });
  });

  it('also accepts a non-function, which is passed directly to setState()', () => {
    const tree = renderIntoDocument(<Counter pass="through" />);
    const base = findRenderedComponentWithType(tree, BaseComponent);

    base.props.updateCounter(18);
    expect(omit(base.props, 'updateCounter')).to.eql({
      counter: 18,
      pass: 'through'
    });
  });

  it('accepts setState() callback', () => {
    const tree = renderIntoDocument(<Counter pass="through" />);
    const base = findRenderedComponentWithType(tree, BaseComponent);
    const spy = sinon.spy();

    base.props.updateCounter(18, spy);
    expect(spy.callCount).to.eql(1);

    base.props.updateCounter(n => n + 1, spy);
    expect(spy.callCount).to.eql(2);
  });

});<commit_msg>Ensure that callback is fired after render<commit_after>import React from 'react';
import { expect } from 'chai';
import omit from 'lodash/object/omit';
import { withState, compose } from 'recompose';
import { BaseComponent, countRenders } from './utils';

import {
  findRenderedComponentWithType,
  renderIntoDocument
} from 'react-addons-test-utils';

describe('withState()', () => {
  const Counter = withState('counter', 'updateCounter', 0)(BaseComponent);

  it('adds a stateful value and a function for updating it', () => {
    expect(Counter.displayName).to.equal(
      'withState(BaseComponent)'
    );

    const tree = renderIntoDocument(<Counter pass="through" />);
    const base = findRenderedComponentWithType(tree, BaseComponent);

    expect(omit(base.props, 'updateCounter')).to.eql({
      counter: 0,
      pass: 'through'
    });

    base.props.updateCounter(n => n + 9);
    base.props.updateCounter(n => n * 2);
    expect(omit(base.props, 'updateCounter')).to.eql({
      counter: 18,
      pass: 'through'
    });
  });

  it('also accepts a non-function, which is passed directly to setState()', () => {
    const tree = renderIntoDocument(<Counter pass="through" />);
    const base = findRenderedComponentWithType(tree, BaseComponent);

    base.props.updateCounter(18);
    expect(omit(base.props, 'updateCounter')).to.eql({
      counter: 18,
      pass: 'through'
    });
  });

  it('accepts setState() callback', () => {
    const Counter2 = compose(
      withState('counter', 'updateCounter', 0),
      countRenders
    )(BaseComponent);

    const tree = renderIntoDocument(<Counter2 pass="through" />);
    const base = findRenderedComponentWithType(tree, BaseComponent);
    const spy = sinon.spy(() => {
      expect(base.props.renderCount).to.equal(2);
    });

    expect(base.props.renderCount).to.equal(1);
    base.props.updateCounter(18, spy);
    expect(spy.callCount).to.eql(1);
  });

});
{'fraction_non_alphanumeric': 0.15819516172873063, 'fraction_numerical': 0.008969828757814623, 'mean_word_length': 3.810457516339869, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '3287370', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1124, 'n_words': 245}