Skip to content

Instantly share code, notes, and snippets.

@nodox
Created January 14, 2018 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nodox/9f7742bfcac71828ab9c9da9db80f421 to your computer and use it in GitHub Desktop.
Save nodox/9f7742bfcac71828ab9c9da9db80f421 to your computer and use it in GitHub Desktop.
Example test
import React from 'react';
import SideNav from '../SideNav';
describe('<SideNav />', () => {
const testData = {
headline: 'Test Headline',
content: 'Yay, we have content!',
location: '/home',
displayMenu: false,
};
const enableSideMenu = jest.fn();
const component = shallow(
<SideNav
data={testData}
location={testData.location}
displayMenu={testData.displayMenu}
enableSideMenu={enableSideMenu} />
);
const props = component.instance().props;
it('should render correctly', () => {
expect(component).toMatchSnapshot();
});
it('should close on link button click', () => {
const linkItems = component.find('.sidenav--list--item');
linkItems.forEach(link => {
// console.log(link.debug());
link.simulate('click');
expect(enableSideMenu).toBeCalledWith(false);
})
});
it('should close on exit button click', () => {
const closeMenuButtion = component.find('.sidenav--close--button');
closeMenuButtion.simulate('click');
expect(enableSideMenu).toBeCalledWith(false);
});
it('should have the right props', () => {
expect(props).toHaveProperty('data');
expect(props).toHaveProperty('location');
expect(props).toHaveProperty('displayMenu');
expect(props).toHaveProperty('enableSideMenu');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment