@samitouri / QOS-React-2 / commits / 97e219e785

improve ReactTestUtils.Simulate documentation

Domenico Matteo committed Jul 21, 2015 at 22:27 UTC 97e219e78592bba72c7fbc4ba0716cbc3fa1cd3e
1 file changed +11 -4
docs/docs/10.4-test-utils.md
+11 -4
@@ -16,15 +16,22 @@ Simulate.{eventName}(DOMElement element, object eventData)
16
17 Simulate an event dispatch on a DOM node with optional `eventData` event data. **This is possibly the single most useful utility in `ReactTestUtils`.**
18
19 -Example usage:
19 +**Clicking an element**
20 +```javascript
21 +var node = React.findDOMNode(this.refs.button);
22 +React.addons.TestUtils.Simulate.click(node);
23 +```
24
25 +**Changing the value of an input field and then pressing ENTER**
26 ```javascript
27 var node = React.findDOMNode(this.refs.input);
23 -React.addons.TestUtils.Simulate.click(node);
24 -React.addons.TestUtils.Simulate.change(node, {target: {value: 'Hello, world'}});
25 -React.addons.TestUtils.Simulate.keyDown(node, {key: "Enter"});
28 +node.value = 'giraffe'
29 +React.addons.TestUtils.Simulate.change(node);
30 +React.addons.TestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
31 ```
32
33 +*note that you will have to provide any event property that you're using in your component (e.g. keyCode, which, etc...) as React is not creating any of these for you*
34 +
35 `Simulate` has a method for every event that React understands.
36
37 ### renderIntoDocument