Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-test-renderer/src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class Updater {
const currentState = this._renderer._newState || publicInstance.state;

if (typeof partialState === 'function') {
partialState = partialState(currentState, publicInstance.props);
partialState = partialState.call(publicInstance, currentState, publicInstance.props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run yarn prettier to reformat this file and CI should pass! 😄

}

// Null and undefined are treated as no-ops.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,27 @@ describe('ReactShallowRenderer', () => {
expect(result.props.children).toEqual(2);
});

it('can access component instance from setState updater function', done => {
let instance;

class SimpleComponent extends React.Component {
state = {};

render() {
instance = this;
return null;
}
}

const shallowRenderer = createRenderer();
shallowRenderer.render(<SimpleComponent />);

instance.setState(function updater(state, props) {
expect(this).toBe(instance);
done();
});
});

it('can setState with a callback', () => {
let instance;

Expand Down