Last active
June 16, 2017 09:44
-
-
Save stipsan/774bb1bac21729b3755f95a2567aefba to your computer and use it in GitHub Desktop.
Testing with Jest: Tip #6
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
import renderer from 'react-test-renderer' | |
import App from '../App' | |
jest.mock('react-router-dom', () => ({ | |
Link: 'Link', | |
Route: ({ children, ...props }) => | |
typeof children === 'function' | |
? children({ match: path === '/somewhere' }) | |
: createElement('Route', props) | |
})) | |
it('should render correctly', () => { | |
const component = renderer.create(<App />) | |
expect(component.toJSON()).toMatchSnapshot() | |
}) |
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
import { Route, Link } from 'react-router-dom' | |
import Somewhere from './Somewhere' | |
import SomewhereElse from './SomewhereElse' | |
const SidebarLink = ({ to, ...rest }) => | |
<Route path={to}> | |
{({ match }) => | |
<li className={match ? 'active' : ''}> | |
<Link to={to} {...rest} /> | |
</li>} | |
</Route> | |
export default () => | |
<div> | |
<ul> | |
<SidebarLink to="/somewhere" /> | |
<SidebarLink to="/somewhere-else" /> | |
</ul> | |
<Route path="/somewhere" component={Somewhere} /> | |
<Route path="/somewhere-else" component={SomewhereElse} /> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment