<commit_before>import React from 'react'
import { renderIntoDocument, findRenderedComponentWithType } from 'react-addons-test-utils'

import withActions from '../src/withActions'
import createDispatcher from '../src/createDispatcher'

const doSomething = () => ({
  type: 'DO_SOMETHING'
})

function Child() {
  return <div/>
}

describe('withActions', () => {
  it('passes wrapped actions in props', t => {
    const dispatcher = createDispatcher()
    const Wrapper = withActions(dispatcher, {
      doSomething
    })(Child)

    const tree = renderIntoDocument(<Wrapper/>)
    console.log(tree)

    expect(tree.type).toBe(Child)

    // Check for actions prop
    expect(
      tree.props.actions &&
      typeof tree.props.actions === 'object' &&
      tree.props.actions.hasOwnProperty('doSomething') &&
      typeof tree.props.actions.doSomething === 'function'
    ).toBeTruthy()

    // Check that actions only contains what we've passed
    expect(Object.keys(tree.props.actions)).toEqual([ 'doSomething' ])
  })

  it('wraps actions to correctly dispatch', t => {
    const dispatcher = createDispatcher()
    const reducer = (state = false, action) => {
      switch (action.type) {
        case 'DO_SOMETHING': return true
        default: return state
      }
    }

    // Keep track of reducer state
    dispatcher.reduce(reducer)

    const Wrapper = withActions(dispatcher, {
      doSomething
    })(Child)

    const tree = renderIntoDocument(<Wrapper/>)

    // Dispatch action returned by doSomething
    tree.props.actions.doSomething()

    expect(dispatcher.getState(reducer)).toBe(true)
  })
})
<commit_msg>Fix withActions testing flaws<commit_after>import React, { Component } from 'react'
import { renderIntoDocument, findRenderedComponentWithType } from 'react-addons-test-utils'

import withActions from '../src/withActions'
import createDispatcher from '../src/createDispatcher'

const doSomething = () => ({
  type: 'DO_SOMETHING'
})

class Child extends Component {
  render() {
    return <div/>
  }
}

describe('withActions', () => {
  it('passes wrapped actions in props', t => {
    const dispatcher = createDispatcher()
    const Wrapper = withActions(dispatcher, {
      doSomething
    })(Child)

    const tree = renderIntoDocument(<Wrapper/>)
    const child = findRenderedComponentWithType(tree, Child)

    // Check for actions prop
    expect(
      child.props.actions &&
      typeof child.props.actions === 'object' &&
      child.props.actions.hasOwnProperty('doSomething') &&
      typeof child.props.actions.doSomething === 'function'
    ).toBeTruthy()

    // Check that actions only contains what we've passed
    expect(Object.keys(child.props.actions)).toEqual([ 'doSomething' ])
  })

  it('wraps actions to correctly dispatch', t => {
    const dispatcher = createDispatcher()
    const reducer = (state, action) => {
      if (state === null || state === undefined) {
        state = false
      }

      switch (action.type) {
        case 'DO_SOMETHING': return true
        default: return state
      }
    }

    // Keep track of reducer state
    dispatcher.reduce(reducer)

    const Wrapper = withActions(dispatcher, {
      doSomething
    })(Child)

    const tree = renderIntoDocument(<Wrapper/>)
    const child = findRenderedComponentWithType(tree, Child)
    expect(dispatcher.getState(reducer)).toBe(false)

    // Dispatch action returned by doSomething
    child.props.actions.doSomething()

    expect(dispatcher.getState(reducer)).toBe(true)
  })
})

{'fraction_non_alphanumeric': 0.12468121280816095, 'fraction_numerical': 0.0, 'mean_word_length': 3.278787878787879, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '5175057', 'n_tokens_mistral': 1031, 'n_tokens_neox': 995, 'n_words': 246}