Skip to content

Commit 779d3ef

Browse files
committedApr 3, 2019
Add updateWithAct to render
To test behaviour that only occurs when props are updated it is necessary to call update on the test instance. However, if the behaviour under test is triggered by a hook, e.g. useEffect then the test will fail because the hook is only triggered after the test has run. This addresses the issue by wrapping the update function with act(). callstack#111
1 parent 1d5e15b commit 779d3ef

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎src/render.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ export default function render(
2626
return {
2727
...getByAPI(instance),
2828
...queryByAPI(instance),
29-
update: renderer.update,
29+
update: (element) => updateWithAct(element, renderer),
3030
unmount: renderer.unmount,
3131
toJSON: renderer.toJSON,
3232
debug: debug(instance, renderer),
3333
};
3434
}
3535

36+
function updateWithAct(element, renderer) {
37+
act(() => renderer.update(element));
38+
}
39+
3640
function renderWithAct(
3741
component: React.Element<any>,
3842
options?: Options

0 commit comments

Comments
 (0)