-
Notifications
You must be signed in to change notification settings - Fork 51k
Rewrite SelectEventPlugin-test to test behavior using Public API (#11299) #11676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
c280f65
fc957a9
e4fbaa4
ae31bef
8d7fff5
e1856a0
9c7bdb6
275b2f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,34 +58,36 @@ describe('SelectEventPlugin', () => { | |
| expect(mouseup).toBe(null); | ||
| }); | ||
|
|
||
| it('should extract if an `onSelect` listener is present', () => { | ||
| class WithSelect extends React.Component { | ||
| render() { | ||
| return <input type="text" onSelect={this.props.onSelect} />; | ||
| } | ||
| } | ||
|
|
||
| var cb = jest.fn(); | ||
|
|
||
| var rendered = ReactTestUtils.renderIntoDocument( | ||
| <WithSelect onSelect={cb} />, | ||
| it('should register event only if the `onSelect` listener is present', () => { | ||
| var select = jest.fn(); | ||
| var onSelect = event => { | ||
| expect(typeof event).toBe('object'); | ||
| expect(event.type).toBe('select'); | ||
| expect(event.target).toBe(node); | ||
| select(event.currentTarget); | ||
| }; | ||
|
|
||
| var childContainer = document.createElement('div'); | ||
| var childNode = ReactDOM.render( | ||
| <input type="text" onSelect={onSelect} />, | ||
| childContainer, | ||
| ); | ||
| var node = ReactDOM.findDOMNode(rendered); | ||
| document.body.appendChild(childContainer); | ||
|
|
||
| node.selectionStart = 0; | ||
| node.selectionEnd = 0; | ||
| var node = ReactDOM.findDOMNode(childNode); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to |
||
| node.focus(); | ||
| expect(select.mock.calls.length).toBe(0); | ||
|
|
||
| var focus = extract(node, 'topFocus'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be testing that a |
||
| expect(focus).toBe(null); | ||
| var nativeEvent = document.createEvent('Event'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use the newer API for this? e.g. |
||
| nativeEvent.initEvent('mousedown', true, true); | ||
| childNode.dispatchEvent(nativeEvent); | ||
| expect(select.mock.calls.length).toBe(0); | ||
|
|
||
| var mousedown = extract(node, 'topMouseDown'); | ||
| expect(mousedown).toBe(null); | ||
| nativeEvent = document.createEvent('Event'); | ||
| nativeEvent.initEvent('mouseup', true, true); | ||
| childNode.dispatchEvent(nativeEvent); | ||
| expect(select.mock.calls.length).toBe(1); | ||
|
|
||
| var mouseup = extract(node, 'topMouseUp'); | ||
| expect(mouseup).not.toBe(null); | ||
| expect(typeof mouseup).toBe('object'); | ||
| expect(mouseup.type).toBe('select'); | ||
| expect(mouseup.target).toBe(node); | ||
| document.body.removeChild(childContainer); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind doing this in
beforeEachand then cleaning up inafterEach? Like here.