title,body,link,tags,view_count,is_answered,score,answer_count,critical points
Tips when testing a connected Redux Component,"<p>I've pasted my Component below which is very, very basic. When the Component is mounted, it will basically call the <code>fetchMessage</code> Action, which returns a message from an API. That message will in turn get set as <code>state.feature.message</code> in the <code>mapStateToProps</code> function.</p>

<p>I'm at a complete loss on where to begin testing this Component. I know that I want to test that:</p>

<p>1) The Feature Component is rendered</p>

<p>2) The <code>fetchMessage</code> function in <code>props</code> is called</p>

<p>3) It displays or has the correct <code>message</code> property when rendered using that</p>

<p>I've tried setting my test file up as you can see below, but I just end up with repeated error after error with everything that I try.</p>

<p>Could anyone point me in the right direction with what I'm doing wrong?</p>

<pre><code>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import * as actions from './actions';

class Feature extends Component {
  static propTypes = {
    fetchMessage: PropTypes.func.isRequired,
    message: PropTypes.string
  }

  componentWillMount() {
    this.props.fetchMessage();
  }

  render() {
    return (
      &lt;div&gt;{this.props.message}&lt;/div&gt;
    );
  }
}

function mapStateToProps(state) {
  return { message: state.feature.message };
}

export default connect(mapStateToProps, actions)(Feature);
</code></pre>

<p>Test file:</p>

<pre><code>import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import expect from 'expect';
import { shallow, render, mount } from 'enzyme';
import React from 'react';
import sinon from 'sinon';

import Feature from '../index';

const mockStore = configureStore([thunk]);

describe('&lt;Feature /&gt;', () =&gt; {
  let store;

  beforeEach(() =&gt; {
    store = mockStore({
      feature: {
        message: 'This is the message'
      }
    });
  });

  it('renders a &lt;Feature /&gt; component and calls fetchMessage', () =&gt; {
    const props = {
      fetchMessage: sinon.spy()
    };

    const wrapper = mount(
      &lt;Provider store={store}&gt;
        &lt;Feature {...props} /&gt;
      &lt;/Provider&gt;
    );

    expect(wrapper.find('Feature').length).toEqual(1);
    expect(props.fetchMessage.calledOnce).toEqual(true);
  });
});
</code></pre>
",https://stackoverflow.com/questions/41448808/tips-when-testing-a-connected-redux-component,"['javascript', 'reactjs', 'testing', 'react-redux', 'enzyme']",299,FALSE,0,2,"The answer is quite code specific, can't be generalized"
Django - beginner tips for test writing?,"<p>I am Django beginner and I need to learn how to write functional and unit tests. I am going to start with documentation, but maybe someone knows good tutorials or has some good tips to share? Should I use ""Selenium"" for functional tests or is it considered a bad practise?</p>

<p>Also I am wondering what percentage of the code should I cover with tests?</p>

<p>Thanks for answers in advance.</p>
",https://stackoverflow.com/questions/30821950/django-beginner-tips-for-test-writing,"['python', 'django', 'selenium', 'testing', 'functional-programming']",116,TRUE,-2,2,Using factories instead of fixtures to write Django tests. Selinium for functional testing
