Skip to content

Commit d2bb655

Browse files
chenesanljharb
authored andcommitted
[fix] mount: invoke: use adapter’s wrapInvoke if present
1 parent 2a862c7 commit d2bb655

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

docs/api/ReactWrapper/invoke.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# `.invoke(propName)(...args) => Any`
22

33
Invokes a function prop.
4+
Note that in React 16.8+, `.invoke` will wrap your handler with [`ReactTestUtils.act`](https://reactjs.org/docs/test-utils.html#act) and call `.update()` automatically.
45

56
#### Arguments
67

packages/enzyme/src/ReactWrapper.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,9 @@ class ReactWrapper {
841841
throw new TypeError('ReactWrapper::invoke() requires the name of a prop whose value is a function');
842842
}
843843
return (...args) => {
844-
const response = handler(...args);
844+
const response = typeof this[RENDERER].wrapInvoke === 'function'
845+
? this[RENDERER].wrapInvoke(() => handler(...args))
846+
: handler(...args);
845847
this[ROOT].update();
846848
return response;
847849
};

0 commit comments

Comments
 (0)