Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export function mount(
}

to.appendChild(el)
app.onUnmount(() => {
to?.removeChild(el)
})
}
const vm = app.mount(el)
if (errorsOnMount.length) {
Expand Down
10 changes: 10 additions & 0 deletions tests/mount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,14 @@
})
expect(wrapper.text()).toContain('Hello world')
})

it('should remove wrapper div when unmount', () => {
expect(document.body.firstChild, 'Container should be empty').toBeNull();

Check failure on line 107 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (20)

Delete `;`

Check failure on line 107 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (24)

Delete `;`

Check failure on line 107 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (22)

Delete `;`

const wrapper = mount(Hello, { props: { msg: 'Hello world' }, attachTo: document.body });

Check failure on line 109 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (20)

Replace `·props:·{·msg:·'Hello·world'·},·attachTo:·document.body·});` with `⏎······props:·{·msg:·'Hello·world'·},⏎······attachTo:·document.body⏎····})`

Check failure on line 109 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (24)

Replace `·props:·{·msg:·'Hello·world'·},·attachTo:·document.body·});` with `⏎······props:·{·msg:·'Hello·world'·},⏎······attachTo:·document.body⏎····})`

Check failure on line 109 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (22)

Replace `·props:·{·msg:·'Hello·world'·},·attachTo:·document.body·});` with `⏎······props:·{·msg:·'Hello·world'·},⏎······attachTo:·document.body⏎····})`
expect(document.body.firstChild, 'Container should have mounted component wrapper').toBeInstanceOf(HTMLDivElement);

Check failure on line 110 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (20)

Replace `document.body.firstChild,·'Container·should·have·mounted·component·wrapper').toBeInstanceOf(HTMLDivElement);` with `⏎······document.body.firstChild,⏎······'Container·should·have·mounted·component·wrapper'⏎····).toBeInstanceOf(HTMLDivElement)`

Check failure on line 110 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (24)

Replace `document.body.firstChild,·'Container·should·have·mounted·component·wrapper').toBeInstanceOf(HTMLDivElement);` with `⏎······document.body.firstChild,⏎······'Container·should·have·mounted·component·wrapper'⏎····).toBeInstanceOf(HTMLDivElement)`

Check failure on line 110 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (22)

Replace `document.body.firstChild,·'Container·should·have·mounted·component·wrapper').toBeInstanceOf(HTMLDivElement);` with `⏎······document.body.firstChild,⏎······'Container·should·have·mounted·component·wrapper'⏎····).toBeInstanceOf(HTMLDivElement)`

Check failure on line 111 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (20)

Delete `····`

Check failure on line 111 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (24)

Delete `····`

Check failure on line 111 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (22)

Delete `····`
wrapper.unmount();

Check failure on line 112 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (20)

Delete `;`

Check failure on line 112 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (24)

Delete `;`

Check failure on line 112 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (22)

Delete `;`
expect(document.body.firstChild, 'Container should be empty').toBeNull();

Check failure on line 113 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (20)

Delete `;`

Check failure on line 113 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (24)

Delete `;`

Check failure on line 113 in tests/mount.spec.ts

View workflow job for this annotation

GitHub Actions / build (22)

Delete `;`
})
})
Loading