Skip to content

Commit

Permalink
fix(ct): mount then unmount then mount (#30657)
Browse files Browse the repository at this point in the history
closes #30628
  • Loading branch information
sand4rt committed May 14, 2024
1 parent 27ce5c0 commit 9ce41fa
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/playwright-ct-react17/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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');
});

0 comments on commit 9ce41fa

Please sign in to comment.