fix(ct): mount then unmount then mount (#30657)

closes https://github.com/microsoft/playwright/issues/30628
This commit is contained in:
Sander 2024-05-14 20:03:46 +02:00 committed by GitHub
parent 27ce5c0226
commit 9ce41fa1b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 99 additions and 0 deletions

View file

@ -86,6 +86,8 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
window.playwrightUnmount = async rootElement => { window.playwrightUnmount = async rootElement => {
if (!__pwReactDOM.unmountComponentAtNode(rootElement)) if (!__pwReactDOM.unmountComponentAtNode(rootElement))
throw new Error('Component was not mounted'); throw new Error('Component was not mounted');
__pwRootRegistry.delete(rootElement);
}; };
window.playwrightUpdate = async (rootElement, component) => { window.playwrightUpdate = async (rootElement, component) => {

View file

@ -23,3 +23,10 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});

View file

@ -23,3 +23,10 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});

View file

@ -23,3 +23,10 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});

View file

@ -31,3 +31,18 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(Button, {
props: {
title: 'Submit',
},
});
await component.unmount();
component = await mount(Button, {
props: {
title: 'Save',
},
});
await expect(component).toContainText('Save');
});

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,19 @@ 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('mount then unmount then mount', async ({ mount }) => {
let component = await mount(Button, {
props: {
title: 'Submit',
},
});
await component.unmount();
component = await mount(Button, {
props: {
title: 'Save',
},
});
await expect(component).toContainText('Save');
});

View file

@ -31,3 +31,18 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(Button, {
props: {
title: 'Submit',
},
});
await component.unmount();
component = await mount(Button, {
props: {
title: 'Save',
},
});
await expect(component).toContainText('Save');
});

View file

@ -16,3 +16,10 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});

View file

@ -21,3 +21,18 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(Button, {
props: {
title: 'Submit',
},
});
await component.unmount();
component = await mount(Button, {
props: {
title: 'Save',
},
});
await expect(component).toContainText('Save');
});

View file

@ -13,3 +13,10 @@ test('unmount twice throws an error', async ({ mount }) => {
await component.unmount(); await component.unmount();
await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); await expect(component.unmount()).rejects.toThrowError('Component was not mounted');
}); });
test('mount then unmount then mount', async ({ mount }) => {
let component = await mount(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});