Last active
September 24, 2017 08:14
-
-
Save koba04/7a3ba84c7ebd61faee2fd2a52c72e6b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react'; | |
import TestRenderer from 'react-test-renderer'; | |
class MyComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.input = null; | |
} | |
componentDidMount() { | |
this.input.focus(); | |
} | |
render() { | |
return <input type="text" ref={el => this.input = el} /> | |
} | |
} | |
let focused = false; | |
TestRenderer.create( | |
<MyComponent />, | |
{ | |
createNodeMock: (element) => { | |
if (element.type === 'input') { | |
// mock a focus function | |
return { | |
focus: () => { | |
focused = true; | |
} | |
}; | |
} | |
return null; | |
} | |
} | |
); | |
console.assert(focused === true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment