From 6ef64ea4a070e83430e1a9ae7d76b8208bf55890 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 15 Jul 2020 14:12:27 +0200 Subject: [PATCH] fix(unmount): Flush useEffect cleanup functions syncronously --- src/__tests__/render.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/__tests__/render.js b/src/__tests__/render.js index 54916ba4..4e78afa6 100644 --- a/src/__tests__/render.js +++ b/src/__tests__/render.js @@ -87,3 +87,17 @@ test('renders options.wrapper around node', () => { `) }) + +test('flushes useEffect cleanup functions sync on unmount()', () => { + const spy = jest.fn() + function Component() { + React.useEffect(() => spy, []) + return null + } + const {unmount} = render() + expect(spy).toHaveBeenCalledTimes(0) + + unmount() + + expect(spy).toHaveBeenCalledTimes(1) +})