facebook/react — pull request #948 by thomasboyt (2014-01-20 23:41:13+00:00)
Title: Implemented nextUpdate() for React testing

Per conversations with @petehunt in IRC, this PR adds a new `nextUpdate(component, callback)` method in ReactTestUtils.

This is a convenience method for adding an additional, one-time `componentDidUpdate` method to a component. It's useful for testing components that are updated asynchronously from outside data sources (such as components that fetch data through AJAX). For example, if you had a component that changed a value that was updated asynchronously, you might test it with something like:

```js
ReactTestUtils.nextUpdate(component, function() {
assert(component.getDOMNode().querySelector('input.foo').value === expected);
done(); // (mocha-style async callback)
});

setTimeout(function() {
component.setState({value: expected});
}, 10);
```

Internally, this creates a new `chainedFunction` like a mixin would, but resets `componentDidUpdate` back to its initial value after the callback was called.