Created
May 11, 2018 17:13
-
-
Save barbaromatrix/7e68d5a747141e15ad130224a2ba02b0 to your computer and use it in GitHub Desktop.
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 { shallow } from 'enzyme'; | |
import PrivateRoute from './Routes.js'; | |
const mockComponent = <h1>Test component</h1>; | |
describe('Routes Unit Test', () => { | |
describe('Happy path', () => { | |
test('It should render a component when isUserLogged is true', () => { | |
const wrapper = shallow(<PrivateRoute component={mockComponent} isUserLogged={true}/>); | |
const { type: { props } } = wrapper.find('Route').props().render(); | |
expect(wrapper.find('Route')).toHaveLength(1); | |
expect(props.children).toEqual('Test component'); | |
}); | |
test('It should redirect to "/" when isUserLogged is false', () => { | |
const wrapper = shallow(<PrivateRoute component={mockComponent} isUserLogged={false}/>); | |
const renderedComponent = wrapper.find('Route').props().render(); | |
expect(wrapper.find('Route')).toHaveLength(1); | |
expect(renderedComponent.props).toHaveProperty('to', '/'); | |
}); | |
}); | |
// describe('Sad Path', () => {}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment