-
-
Save oieduardorabelo/c3a6a7f0bf3983231a55895a81af9c80 to your computer and use it in GitHub Desktop.
Testando com Jest: Dica #6
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 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 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