Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to call a setState callback after finishing the the render #1453

Merged
merged 6 commits into from
Jan 6, 2018
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
Prev Previous commit
Next Next commit
Add comments for an argument of setState callback
  • Loading branch information
koba04 authored and ljharb committed Jan 4, 2018
commit 30b4556add8908f7bf632ea4622f14f8b3f6b1ff
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from 'enzyme-adapter-utils';

const MINOR_VERSION = React.version.split('.')[1];
const CALLING_SETSTATE_CALLBACK_WITH_UNDEFINED = MINOR_VERSION >= 4;

function compositeTypeToNodeType(type) {
switch (type) {
Expand Down Expand Up @@ -257,7 +256,8 @@ class ReactFifteenFourAdapter extends EnzymeAdapter {
}

invokeSetStateCallback(instance, callback) {
if (CALLING_SETSTATE_CALLBACK_WITH_UNDEFINED) {
// React in <= 15.3, and >= 16 pass undefined to a setState callback
if (MINOR_VERSION >= 4) {
callback.call(instance, undefined);
} else {
callback.call(instance);
Copy link
Member

Choose a reason for hiding this comment

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

maybe this could do super.invokeSetStateCallback(instance, callback)?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class ReactFifteenAdapter extends EnzymeAdapter {
}

invokeSetStateCallback(instance, callback) {
// React in <= 15.3, and >= 16 pass undefined to a setState callback
callback.call(instance, undefined);
}
}
Expand Down