Skip to content

Commit

Permalink
+ withClickOut hoc spec
Browse files Browse the repository at this point in the history
  • Loading branch information
carloluis committed Sep 23, 2017
1 parent 2940568 commit 330ce24
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/__tests__/noop.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import noop from '../noop';

describe('noop', () => {
it('should always return undefined', () => {
it('should return nothing', () => {
const result = noop();
expect(result).toBe(undefined);
});
Expand Down
34 changes: 34 additions & 0 deletions src/utils/__tests__/withClickOut.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import withClickOut from '../withClickOut';
import { shallow, mount } from 'enzyme';

function TestComponent(props) {
return <div ref={props.reference}/>;
}

describe('withClickOut', () => {
const WrappedComponent = withClickOut(TestComponent);

it('should set correct displayName in wrapped component', () => {
expect(WrappedComponent.displayName).toBe('ClickOut(TestComponent)');
});

it('should render <TestComponent>', () => {
const tree = shallow(<WrappedComponent />);
expect(tree.find('TestComponent').getNode()).toBeTruthy();
});

it('shoud add a click event listener to the document', () => {
const addEventListenerSpy = jest.spyOn(document, 'addEventListener');
const tree = mount(<WrappedComponent />);
expect(addEventListenerSpy).toBeCalledWith('click', tree.instance().handleClick);
});

it('shoud remove the click event listener to the document', () => {
const removeEventListenerSpy = jest.spyOn(document, 'removeEventListener');
const tree = mount(<WrappedComponent />);
const handleClick = tree.instance().handleClick;
tree.unmount();
expect(removeEventListenerSpy).toBeCalledWith('click', handleClick);
});
});

0 comments on commit 330ce24

Please sign in to comment.