diff --git a/src/__tests__/render.test.js b/src/__tests__/render.test.js
index a6f7d6437..8b36a9e4f 100644
--- a/src/__tests__/render.test.js
+++ b/src/__tests__/render.test.js
@@ -282,6 +282,20 @@ test('unmount', () => {
expect(fn).toHaveBeenCalled();
});
+test('unmount should handle cleanup functions', () => {
+ const cleanup = jest.fn();
+ const Component = () => {
+ React.useEffect(() => cleanup);
+ return null;
+ };
+
+ const { unmount } = render();
+
+ unmount();
+
+ expect(cleanup).toHaveBeenCalledTimes(1);
+});
+
test('toJSON', () => {
const { toJSON } = render(press me);
diff --git a/src/render.js b/src/render.js
index cb9daeaad..e6323d58d 100644
--- a/src/render.js
+++ b/src/render.js
@@ -46,8 +46,13 @@ export default function render(
);
const update = updateWithAct(renderer, wrap);
const instance = renderer.root;
+ const unmount = () => {
+ act(() => {
+ renderer.unmount();
+ });
+ };
- addToCleanupQueue(renderer.unmount);
+ addToCleanupQueue(unmount);
return {
...getByAPI(instance),
@@ -55,9 +60,9 @@ export default function render(
...findByAPI(instance),
...a11yAPI(instance),
update,
+ unmount,
container: instance,
rerender: update, // alias for `update`
- unmount: renderer.unmount,
toJSON: renderer.toJSON,
debug: debug(instance, renderer),
};