Skip to content

Commit

Permalink
Merge pull request #4451 from dmatteo/TestUtils.Simulate-docs
Browse files Browse the repository at this point in the history
improve ReactTestUtils.Simulate documentation
  • Loading branch information
zpao committed Aug 17, 2015
2 parents d984b68 + 97e219e commit b4ee5b5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions docs/docs/10.4-test-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@ Simulate.{eventName}(DOMElement element, object eventData)

Simulate an event dispatch on a DOM node with optional `eventData` event data. **This is possibly the single most useful utility in `ReactTestUtils`.**

Example usage:
**Clicking an element**
```javascript
var node = React.findDOMNode(this.refs.button);
React.addons.TestUtils.Simulate.click(node);
```

**Changing the value of an input field and then pressing ENTER**
```javascript
var node = React.findDOMNode(this.refs.input);
React.addons.TestUtils.Simulate.click(node);
React.addons.TestUtils.Simulate.change(node, {target: {value: 'Hello, world'}});
React.addons.TestUtils.Simulate.keyDown(node, {key: "Enter"});
node.value = 'giraffe'
React.addons.TestUtils.Simulate.change(node);
React.addons.TestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
```

*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*

`Simulate` has a method for every event that React understands.

### renderIntoDocument
Expand Down

0 comments on commit b4ee5b5

Please sign in to comment.