feat(ct): double unmounting component throws error (#29650)

This commit is contained in:
Sander 2024-02-26 20:16:27 +01:00 committed by GitHub
parent 303d7fdac9
commit 015a1bcc1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 92 additions and 0 deletions

View file

@ -72,6 +72,7 @@ window.playwrightUnmount = async rootElement => {
throw new Error('Component was not mounted'); throw new Error('Component was not mounted');
unmount(); unmount();
delete rootElement[__pwUnmountKey];
}; };
window.playwrightUpdate = async (rootElement, component) => { window.playwrightUpdate = async (rootElement, component) => {

View file

@ -108,6 +108,7 @@ window.playwrightUnmount = async rootElement => {
if (!svelteComponent) if (!svelteComponent)
throw new Error('Component was not mounted'); throw new Error('Component was not mounted');
svelteComponent.$destroy(); svelteComponent.$destroy();
delete rootElement[__pwSvelteComponentKey];
}; };
window.playwrightUpdate = async (rootElement, component) => { window.playwrightUpdate = async (rootElement, component) => {

View file

@ -256,6 +256,7 @@ window.playwrightUnmount = async rootElement => {
if (!app) if (!app)
throw new Error('Component was not mounted'); throw new Error('Component was not mounted');
app.unmount(); app.unmount();
delete rootElement[__pwAppKey];
}; };
window.playwrightUpdate = async (rootElement, component) => { window.playwrightUpdate = async (rootElement, component) => {

View file

@ -182,6 +182,7 @@ window.playwrightUnmount = async rootElement => {
throw new Error('Component was not mounted'); throw new Error('Component was not mounted');
component.$destroy(); component.$destroy();
component.$el.remove(); component.$el.remove();
delete rootElement[instanceKey];
}; };
window.playwrightUpdate = async (element, options) => { window.playwrightUpdate = async (element, options) => {

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -1,5 +1,6 @@
import { test, expect } from '@playwright/experimental-ct-vue'; import { test, expect } from '@playwright/experimental-ct-vue';
import MultiRoot from '@/components/MultiRoot.vue'; import MultiRoot from '@/components/MultiRoot.vue';
import Button from '@/components/Button.vue';
test('unmount a multi root component', async ({ mount, page }) => { test('unmount a multi root component', async ({ mount, page }) => {
const component = await mount(<MultiRoot />); 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 1');
await expect(page.locator('#root')).not.toContainText('root 2'); 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');
});

View file

@ -11,3 +11,13 @@ test('unmount', async ({ page, mount }) => {
await component.unmount(); await component.unmount();
await expect(page.locator('#root')).not.toContainText('Submit'); 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');
});

View file

@ -7,3 +7,9 @@ test('unmount', async ({ page, mount }) => {
await component.unmount(); await component.unmount();
await expect(page.locator('#root')).not.toContainText('Submit'); 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');
});