@@ -4,7 +4,6 @@ import { createStore } from 'redux';
44import { Provider , connect } from 'react-redux' ;
55import { render , fireEvent } from '../../src' ;
66
7- // counter.js
87class Counter extends React . Component {
98 increment = ( ) => {
109 this . props . dispatch ( { type : 'INCREMENT' } ) ;
@@ -28,13 +27,8 @@ class Counter extends React.Component {
2827 }
2928}
3029
31- // normally this would be:
32- // export default connect(state => ({count: state.count}))(Counter)
33- // but for this test we'll give it a variable name
34- // because we're doing this all in one file
3530const ConnectedCounter = connect ( state => ( { count : state . count } ) ) ( Counter ) ;
3631
37- // app.js
3832function reducer ( state = { count : 0 } , action ) {
3933 switch ( action . type ) {
4034 case 'INCREMENT' :
@@ -50,27 +44,9 @@ function reducer(state = { count: 0 }, action) {
5044 }
5145}
5246
53- // normally here you'd do:
54- // const store = createStore(reducer)
55- // ReactDOM.render(
56- // <Provider store={store}>
57- // <Counter />
58- // </Provider>,
59- // document.getElementById('root'),
60- // )
61- // but for this test we'll umm... not do that :)
62-
63- // Now here's what your test will look like:
64-
65- // this is a handy function that I normally make available for all my tests
66- // that deal with connected components.
67- // you can provide initialState or the entire store that the ui is rendered with
6847function renderWithRedux ( ui , { initialState, store = createStore ( reducer , initialState ) } = { } ) {
6948 return {
7049 ...render ( < Provider store = { store } > { ui } </ Provider > ) ,
71- // adding `store` to the returned utilities to allow us
72- // to reference it in our tests (just try to avoid using
73- // this to test implementation details).
7450 store,
7551 } ;
7652}
@@ -90,7 +66,6 @@ test('can render with redux with custom initial state', () => {
9066} ) ;
9167
9268test ( 'can render with redux with custom store' , ( ) => {
93- // this is a silly store that can never be changed
9469 const store = createStore ( ( ) => ( { count : 1000 } ) ) ;
9570 const { getByTestId, getByText } = renderWithRedux ( < ConnectedCounter /> , {
9671 store,
0 commit comments