Skip to content

Instantly share code, notes, and snippets.

@oieduardorabelo
Forked from stipsan/Sidebar-test.jsx
Last active June 16, 2017 09:43
Show Gist options
  • Save oieduardorabelo/7713726cd50e89a91dfa55076a54706c to your computer and use it in GitHub Desktop.
Save oieduardorabelo/7713726cd50e89a91dfa55076a54706c to your computer and use it in GitHub Desktop.
Testando com Jest: Dica #5
import renderer from 'react-test-renderer'
import Sidebar from '../Sidebar'
jest.mock('react-router-dom', () => ({
Link: 'Link',
Route: ({ children, path }) => children({ match: path === '/somewhere' })
}))
it('should render correctly', () => {
const component = renderer.create(<Sidebar />)
expect(component.toJSON()).toMatchSnapshot()
})
import { Route, Link } from 'react-router-dom'
const SidebarLink = ({ to, ...rest }) =>
<Route path={to}>
{({ match }) =>
<li className={match ? 'active' : ''}>
<Link to={to} {...rest} />
</li>}
</Route>
export default () =>
<ul>
<SidebarLink to="/somewhere" />
<SidebarLink to="/somewhere-else" />
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment