Skip to content

Commit ec3beef

Browse files
committed
[Fix] mount: setState: invoke callback with the proper receiver
1 parent 8feee5a commit ec3beef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/enzyme/src/ReactWrapper.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,19 +298,23 @@ class ReactWrapper {
298298
* @param {Function} cb - callback function
299299
* @returns {ReactWrapper}
300300
*/
301-
setState(state, callback = noop) {
301+
setState(state, callback = undefined) {
302302
if (this[ROOT] !== this) {
303303
throw new Error('ReactWrapper::setState() can only be called on the root');
304304
}
305305
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') {
306306
throw new Error('ReactWrapper::setState() can only be called on class components');
307307
}
308-
if (typeof callback !== 'function') {
308+
if (arguments.length > 1 && typeof callback !== 'function') {
309309
throw new TypeError('ReactWrapper::setState() expects a function as its second argument');
310310
}
311311
this.instance().setState(state, () => {
312312
this.update();
313-
callback();
313+
if (callback) {
314+
const adapter = getAdapter(this[OPTIONS]);
315+
const instance = this.instance();
316+
adapter.invokeSetStateCallback(instance, callback);
317+
}
314318
});
315319
return this;
316320
}

0 commit comments

Comments
 (0)