Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/playwright-ct-react17/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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) => {
Expand Down
7 changes: 7 additions & 0 deletions tests/components/ct-react-vite/tests/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});
7 changes: 7 additions & 0 deletions tests/components/ct-react17/tests/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});
7 changes: 7 additions & 0 deletions tests/components/ct-solid/tests/unmount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});
15 changes: 15 additions & 0 deletions tests/components/ct-svelte-vite/tests/unmount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,18 @@ 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(Button, {
props: {
title: 'Submit',
},
});
await component.unmount();
component = await mount(Button, {
props: {
title: 'Save',
},
});
await expect(component).toContainText('Save');
});
17 changes: 17 additions & 0 deletions tests/components/ct-vue-vite/tests/unmount/unmount.spec.js
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,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 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');
});

15 changes: 15 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 @@ -31,3 +31,18 @@ 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(Button, {
props: {
title: 'Submit',
},
});
await component.unmount();
component = await mount(Button, {
props: {
title: 'Save',
},
});
await expect(component).toContainText('Save');
});
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
Expand Up @@ -16,3 +16,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(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});
15 changes: 15 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 @@ -21,3 +21,18 @@ 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(Button, {
props: {
title: 'Submit',
},
});
await component.unmount();
component = await mount(Button, {
props: {
title: 'Save',
},
});
await expect(component).toContainText('Save');
});
7 changes: 7 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 @@ -13,3 +13,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(<Button title="Submit" />);
await component.unmount();
component = await mount(<Button title="Save" />);
await expect(component).toContainText('Save');
});