Created
August 17, 2016 17:48
-
-
Save alicekao/613889c70e540bce68fd20de33c14eea to your computer and use it in GitHub Desktop.
Testing connected redux components
This file contains hidden or 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
// Header component to test in header.js | |
import React, {Component} from 'react'; | |
import { Link } from 'react-router'; | |
export class Header extends Component { // Here we export our class | |
render() { | |
const { logoutUser } = this.props; | |
return ( | |
<nav className="navbar navbar-light"> | |
<Link className='navbar-brand' to="/">PinPointMe</Link> | |
<ul className='nav navbar-nav'> | |
<li className='nav-item pull-right'> | |
<a href="#" className='nav-link' onClick={ logoutUser }>Sign out</a> | |
</li> | |
</ul> | |
</nav> | |
); | |
} | |
} | |
function mapStateToProps(state) { | |
return { | |
isAuth: state.auth.isAuthenticated | |
}; | |
} | |
export default connect(mapStateToProps, actions)(Header); // We export our connected component by default | |
// Now in our header.spec.js we can pull out the unconnected component | |
import { Header } from './header'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment