Last active
August 25, 2016 22:02
-
-
Save zedd45/cbc981e385dc33d6920d7fcb55e7a3e0 to your computer and use it in GitHub Desktop.
Redux: cannot read displayName of undefined (Redux + Karma Webpack)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { connect } from 'react-redux'; | |
import EventTableComponent from './EventTableComponent'; | |
import { fetchData } from '../../actions'; | |
const mapStateToProps = (state, ownProps) => { | |
return { | |
// state mapping here | |
}; | |
}; | |
export default connect(mapStateToProps, { fetchData })(EventTableComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component, PropTypes } from 'react'; | |
export default class EventTable extends Component { | |
static propTypes = { | |
//.. | |
}; | |
static defaultProps = { | |
// .. | |
}; | |
constructor (props) { | |
super(props); | |
this.handleClick = this.handleClick.bind(this); | |
this.state = { | |
expanded: props.collapsible ? props.expanded : true, | |
}; | |
} | |
componentWillMount () { | |
// data is fetched here | |
} | |
shouldComponentUpdate (nextProps, nextState) { | |
const { isLoading, event } = this.props; | |
const { expanded } = this.state; | |
return nextProps.isLoading !== isLoading || | |
nextProps.event.id !== event.id || | |
nextState.expanded !== expanded; | |
} | |
handleClick () { | |
this.setState({ expanded: !this.state.expanded }); | |
} | |
render () { | |
// lots of destructuring here | |
const tableToRender = renderMyContestTable ? | |
(<MyContestTable rows={this.state.expanded ? tableRows : []} />) : | |
(<LobbyTable rows={this.state.expanded ? tableRows : []} />); | |
return ( | |
<span> | |
<div className={classes}> | |
{isLoading ? 'loading...' : tableToRender } | |
</div> | |
// footer here | |
</span> | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chai from 'chai'; | |
import React from 'react'; | |
import EventTableComponent from '../EventTableComponent'; | |
import TestUtils from 'react-addons-test-utils'; | |
describe('React.Component: EventTable', () => { | |
describe('...', () => { | |
let table; | |
beforeEach(() => { | |
table = TestUtils.renderIntoDocument( | |
<EventTableComponent | |
// ... lots of props | |
/> | |
); | |
}); | |
afterEach(() => { | |
table = null; | |
}); | |
it('...', () => { | |
// assertions | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from 'react-redux'; | |
import EventTableComponent from './EventTableComponent'; | |
import { fetchData } from '../../actions'; | |
const mapStateToProps = (state, ownProps) => { | |
return { | |
// ... | |
}; | |
}; | |
export default connect(mapStateToProps, { fetchData })(EventTableComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { connect } from 'react-redux'; | |
// import EventTableComponent from './EventTableComponent'; | |
import { fetchPools as fetchPoolData } from '../../actions'; | |
export function EventTableComponent () { | |
return (<div>hi karma webpack, why do you mock me? heh... get it?</div>); | |
} | |
const mapStateToProps = (state, ownProps) => { | |
return { | |
// data | |
}; | |
}; | |
export default connect(mapStateToProps, { fetchPools: fetchPoolData })(EventTableComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment