-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
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
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
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); | ||
}); | ||
}); |