Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(ct): double unmounting component throws error (#29650)
Sander015a1bcc1c0b
diff --git a/packages/playwright-ct-solid/registerSource.mjs b/packages/playwright-ct-solid/registerSource.mjsindex c89caa7bd8..d0077dd494 100644--- a/packages/playwright-ct-solid/registerSource.mjs+++ b/packages/playwright-ct-solid/registerSource.mjs@@ -72,6 +72,7 @@ window.playwrightUnmount = async rootElement => {throw new Error('Component was not mounted');unmount();+ delete rootElement[__pwUnmountKey];};window.playwrightUpdate = async (rootElement, component) => {diff --git a/packages/playwright-ct-svelte/registerSource.mjs b/packages/playwright-ct-svelte/registerSource.mjsindex b11f8e0369..642548f18a 100644--- a/packages/playwright-ct-svelte/registerSource.mjs+++ b/packages/playwright-ct-svelte/registerSource.mjs@@ -108,6 +108,7 @@ window.playwrightUnmount = async rootElement => {if (!svelteComponent)throw new Error('Component was not mounted');svelteComponent.$destroy();+ delete rootElement[__pwSvelteComponentKey];};window.playwrightUpdate = async (rootElement, component) => {diff --git a/packages/playwright-ct-vue/registerSource.mjs b/packages/playwright-ct-vue/registerSource.mjsindex 198372cc38..07ce5298f4 100644--- a/packages/playwright-ct-vue/registerSource.mjs+++ b/packages/playwright-ct-vue/registerSource.mjs@@ -256,6 +256,7 @@ window.playwrightUnmount = async rootElement => {if (!app)throw new Error('Component was not mounted');app.unmount();+ delete rootElement[__pwAppKey];};window.playwrightUpdate = async (rootElement, component) => {diff --git a/packages/playwright-ct-vue2/registerSource.mjs b/packages/playwright-ct-vue2/registerSource.mjsindex b0a7ae71dc..19b4d41c08 100644--- a/packages/playwright-ct-vue2/registerSource.mjs+++ b/packages/playwright-ct-vue2/registerSource.mjs@@ -182,6 +182,7 @@ window.playwrightUnmount = async rootElement => {throw new Error('Component was not mounted');component.$destroy();component.$el.remove();+ delete rootElement[instanceKey];};window.playwrightUpdate = async (element, options) => {diff --git a/tests/components/ct-react-vite/tests/unmount.spec.tsx b/tests/components/ct-react-vite/tests/unmount.spec.tsxindex acc11c4fdb..20374d8b8e 100644--- a/tests/components/ct-react-vite/tests/unmount.spec.tsx+++ b/tests/components/ct-react-vite/tests/unmount.spec.tsx@@ -17,3 +17,9 @@ test('unmount a multi root component', async ({ mount, page }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(<Button title="Submit" />);+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-react17/tests/unmount.spec.tsx b/tests/components/ct-react17/tests/unmount.spec.tsxindex ff9d152b59..8f55829da5 100644--- a/tests/components/ct-react17/tests/unmount.spec.tsx+++ b/tests/components/ct-react17/tests/unmount.spec.tsx@@ -17,3 +17,9 @@ test('unmount a multi root component', async ({ page, mount }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(<Button title="Submit" />);+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-solid/tests/unmount.spec.tsx b/tests/components/ct-solid/tests/unmount.spec.tsxindex 45e715cdf6..5bb38c641b 100644--- a/tests/components/ct-solid/tests/unmount.spec.tsx+++ b/tests/components/ct-solid/tests/unmount.spec.tsx@@ -17,3 +17,9 @@ test('unmount a multi root component', async ({ mount, page }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(<Button title="Submit" />);+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-svelte-vite/tests/unmount.spec.ts b/tests/components/ct-svelte-vite/tests/unmount.spec.tsindex bf0898804f..23e53b8529 100644--- a/tests/components/ct-svelte-vite/tests/unmount.spec.ts+++ b/tests/components/ct-svelte-vite/tests/unmount.spec.ts@@ -21,3 +21,13 @@ test('unmount a multi root component', async ({ mount, page }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(Button, {+ props: {+ title: 'Submit',+ },+ });+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-svelte/tests/unmount.spec.ts b/tests/components/ct-svelte/tests/unmount.spec.tsindex 9be4d9e7e1..c0ac0f6785 100644--- a/tests/components/ct-svelte/tests/unmount.spec.ts+++ b/tests/components/ct-svelte/tests/unmount.spec.ts@@ -21,3 +21,13 @@ test('unmount a multi root component', async ({ page, mount }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(Button, {+ props: {+ title: 'Submit',+ },+ });+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-vue-cli/tests/unmount/unmount.spec.ts b/tests/components/ct-vue-cli/tests/unmount/unmount.spec.tsindex 0077cdfed5..81e4686173 100644--- a/tests/components/ct-vue-cli/tests/unmount/unmount.spec.ts+++ b/tests/components/ct-vue-cli/tests/unmount/unmount.spec.ts@@ -21,3 +21,14 @@ test('unmount a multi root component', async ({ mount, page }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(Button, {+ props: {+ title: 'Submit',+ },+ });+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});+diff --git a/tests/components/ct-vue-cli/tests/unmount/unmount.spec.tsx b/tests/components/ct-vue-cli/tests/unmount/unmount.spec.tsxindex 840b4c5158..614fd784c9 100644--- a/tests/components/ct-vue-cli/tests/unmount/unmount.spec.tsx+++ b/tests/components/ct-vue-cli/tests/unmount/unmount.spec.tsx@@ -17,3 +17,9 @@ test('unmount a multi root component', async ({ mount, page }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(<Button title="Submit" />);+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-vue-vite/tests/unmount/unmount.spec.ts b/tests/components/ct-vue-vite/tests/unmount/unmount.spec.tsindex 0077cdfed5..2eb99ccd82 100644--- a/tests/components/ct-vue-vite/tests/unmount/unmount.spec.ts+++ b/tests/components/ct-vue-vite/tests/unmount/unmount.spec.ts@@ -21,3 +21,13 @@ test('unmount a multi root component', async ({ mount, page }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(Button, {+ props: {+ title: 'Submit',+ },+ });+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-vue-vite/tests/unmount/unmount.spec.tsx b/tests/components/ct-vue-vite/tests/unmount/unmount.spec.tsxindex 967ac97e0d..f4a51893f1 100644--- a/tests/components/ct-vue-vite/tests/unmount/unmount.spec.tsx+++ b/tests/components/ct-vue-vite/tests/unmount/unmount.spec.tsx@@ -1,5 +1,6 @@import { test, expect } from '@playwright/experimental-ct-vue';import MultiRoot from '@/components/MultiRoot.vue';+import Button from '@/components/Button.vue';test('unmount a multi root component', async ({ mount, page }) => {const component = await mount(<MultiRoot />);@@ -9,3 +10,9 @@ test('unmount a multi root component', async ({ mount, page }) => {await expect(page.locator('#root')).not.toContainText('root 1');await expect(page.locator('#root')).not.toContainText('root 2');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(<Button title="Submit" />);+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.ts b/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.tsindex b4a21341d8..4ed68f6c3f 100644--- a/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.ts+++ b/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.ts@@ -11,3 +11,13 @@ test('unmount', async ({ page, mount }) => {await component.unmount();await expect(page.locator('#root')).not.toContainText('Submit');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(Button, {+ props: {+ title: 'Submit',+ },+ });+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});diff --git a/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.tsx b/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.tsxindex ece46931fa..224a601183 100644--- a/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.tsx+++ b/tests/components/ct-vue2-cli/tests/unmount/unmount.spec.tsx@@ -7,3 +7,9 @@ test('unmount', async ({ page, mount }) => {await component.unmount();await expect(page.locator('#root')).not.toContainText('Submit');});++test('unmount twice throws an error', async ({ mount }) => {+ const component = await mount(<Button title="Submit" />);+ await component.unmount();+ await expect(component.unmount()).rejects.toThrowError('Component was not mounted');+});