From 779d3ef9894e27dc5d76109a62bd616bfea56e8e Mon Sep 17 00:00:00 2001 From: ccfz Date: Wed, 3 Apr 2019 08:58:21 +0200 Subject: [PATCH] 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(). https://github.com/callstack/react-native-testing-library/issues/111 --- src/render.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/render.js b/src/render.js index 147175427..1ff36b86f 100644 --- a/src/render.js +++ b/src/render.js @@ -26,13 +26,17 @@ export default function render( return { ...getByAPI(instance), ...queryByAPI(instance), - update: renderer.update, + update: (element) => updateWithAct(element, renderer), unmount: renderer.unmount, toJSON: renderer.toJSON, debug: debug(instance, renderer), }; } +function updateWithAct(element, renderer) { + act(() => renderer.update(element)); +} + function renderWithAct( component: React.Element, options?: Options