Skip to content

Instantly share code, notes, and snippets.

@barbaromatrix
Created May 11, 2018 17:13
Show Gist options
  • Save barbaromatrix/7e68d5a747141e15ad130224a2ba02b0 to your computer and use it in GitHub Desktop.
Save barbaromatrix/7e68d5a747141e15ad130224a2ba02b0 to your computer and use it in GitHub Desktop.
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