Skip to content

Commit

Permalink
feat(ct): double unmounting component throws error (#29650)
Browse files Browse the repository at this point in the history
  • Loading branch information
sand4rt authored Feb 26, 2024
1 parent 303d7fd commit 015a1bc
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/playwright-ct-solid/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ window.playwrightUnmount = async rootElement => {
throw new Error('Component was not mounted');

unmount();
delete rootElement[__pwUnmountKey];
};

window.playwrightUpdate = async (rootElement, component) => {
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-ct-svelte/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-ct-vue/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-ct-vue2/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 6 additions & 0 deletions tests/components/ct-react-vite/tests/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
6 changes: 6 additions & 0 deletions tests/components/ct-react17/tests/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
6 changes: 6 additions & 0 deletions tests/components/ct-solid/tests/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
10 changes: 10 additions & 0 deletions tests/components/ct-svelte-vite/tests/unmount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
10 changes: 10 additions & 0 deletions tests/components/ct-svelte/tests/unmount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
11 changes: 11 additions & 0 deletions tests/components/ct-vue-cli/tests/unmount/unmount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

6 changes: 6 additions & 0 deletions tests/components/ct-vue-cli/tests/unmount/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
10 changes: 10 additions & 0 deletions tests/components/ct-vue-vite/tests/unmount/unmount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
7 changes: 7 additions & 0 deletions tests/components/ct-vue-vite/tests/unmount/unmount.spec.tsx
Original file line number Diff line number Diff line change
@@ -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 />);
Expand All @@ -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');
});
10 changes: 10 additions & 0 deletions tests/components/ct-vue2-cli/tests/unmount/unmount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
6 changes: 6 additions & 0 deletions tests/components/ct-vue2-cli/tests/unmount/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 015a1bc

Please sign in to comment.