facebook/react — pull request #1293 by thomasboyt (2014-03-23 23:26:14+00:00)
Title: Implemented nextUpdate() for ReactTestUtils

This is an updated version of #948 (now on a different fork's repo), original comment below:

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 in Mocha it with something like:

```js
it('updates the value of input.foo with the current state.value', function(done) {
expect(1);

ReactTestUtils.nextUpdate(component, function() {
expect(component.getDOMNode().querySelector('input.foo').value).to.be(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.