From 9ce41fa1b09b16de311e93a0cf29eaacaaf8aa56 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 14 May 2024 20:03:46 +0200 Subject: [PATCH] fix(ct): mount then unmount then mount (#30657) closes https://github.com/microsoft/playwright/issues/30628 --- .../playwright-ct-react17/registerSource.mjs | 2 ++ .../ct-react-vite/tests/unmount.spec.tsx | 7 +++++++ .../ct-react17/tests/unmount.spec.tsx | 7 +++++++ .../components/ct-solid/tests/unmount.spec.tsx | 7 +++++++ .../ct-svelte-vite/tests/unmount.spec.ts | 15 +++++++++++++++ .../ct-vue-vite/tests/unmount/unmount.spec.js | 17 +++++++++++++++++ .../ct-vue-vite/tests/unmount/unmount.spec.ts | 15 +++++++++++++++ .../ct-vue-vite/tests/unmount/unmount.spec.tsx | 7 +++++++ .../ct-vue2-cli/tests/unmount/unmount.spec.ts | 15 +++++++++++++++ .../ct-vue2-cli/tests/unmount/unmount.spec.tsx | 7 +++++++ 10 files changed, 99 insertions(+) diff --git a/packages/playwright-ct-react17/registerSource.mjs b/packages/playwright-ct-react17/registerSource.mjs index 1c484b2b12..50a888b92a 100644 --- a/packages/playwright-ct-react17/registerSource.mjs +++ b/packages/playwright-ct-react17/registerSource.mjs @@ -86,6 +86,8 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => { window.playwrightUnmount = async rootElement => { if (!__pwReactDOM.unmountComponentAtNode(rootElement)) throw new Error('Component was not mounted'); + + __pwRootRegistry.delete(rootElement); }; window.playwrightUpdate = async (rootElement, component) => { diff --git a/tests/components/ct-react-vite/tests/unmount.spec.tsx b/tests/components/ct-react-vite/tests/unmount.spec.tsx index 20374d8b8e..4ce2d45889 100644 --- a/tests/components/ct-react-vite/tests/unmount.spec.tsx +++ b/tests/components/ct-react-vite/tests/unmount.spec.tsx @@ -23,3 +23,10 @@ test('unmount twice throws an error', async ({ mount }) => { await component.unmount(); await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); }); + +test('mount then unmount then mount', async ({ mount }) => { + let component = await mount(