Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Note that when mocking dates/timers with Vitest, this must be called after

```ts
interface MountingOptions<Props, Data = {}> {
attachTo?: HTMLElement | string
attachTo?: Element | string
attrs?: Record<string, unknown>
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
props?: (RawProps & Props) | ({} extends Props ? null : never)
Expand Down Expand Up @@ -74,7 +74,7 @@ Specify the node to mount the component on. This is not available when using `re
**Signature:**

```ts
attachTo?: HTMLElement | string
attachTo?: Element | string
```

**Details:**
Expand Down Expand Up @@ -1882,7 +1882,7 @@ Creates a Wrapper that contains the mounted and rendered Vue component to test w

```ts
interface MountingOptions<Props, Data = {}> {
attachTo?: HTMLElement | string
attachTo?: Element | string
attrs?: Record<string, unknown>
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
props?: (RawProps & Props) | ({} extends Props ? null : never)
Expand Down
6 changes: 3 additions & 3 deletions docs/fr/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Crée un `Wrapper` qui contient le composant Vue monté et rendu pour le test.

```ts
interface MountingOptions<Props, Data = {}> {
attachTo?: HTMLElement | string
attachTo?: Element | string
attrs?: Record<string, unknown>
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
props?: (RawProps & Props) | ({} extends Props ? null : never)
Expand Down Expand Up @@ -72,7 +72,7 @@ Spécifie le nœud où monter le composant.
**Signature&nbsp;:**

```ts
attachTo?: HTMLElement | string
attachTo?: Element | string
```

**Utilisation&nbsp;:**
Expand Down Expand Up @@ -1870,7 +1870,7 @@ Crée un `Wrapper` qui contient le composant Vue monté et rendu pour le tester

```ts
interface MountingOptions<Props, Data = {}> {
attachTo?: HTMLElement | string
attachTo?: Element | string
attrs?: Record<string, unknown>
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
props?: (RawProps & Props) | ({} extends Props ? null : never)
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface MountingOptions<Props, Data = {}>
* Can be a valid CSS selector, or an Element connected to the document.
* @see https://test-utils.vuejs.org/api/#attachto
*/
attachTo?: HTMLElement | string
attachTo?: Element | string
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/mountingOptions/attachTo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ describe('options.attachTo', () => {
wrapper.unmount()
expect(document.getElementById('attach-to')).toBeNull()
})
it('attaches to a provided SVGElement', () => {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg.id = 'root'
document.body.appendChild(svg)
expect(document.getElementById('root')).not.toBeNull()
expect(document.getElementById('attach-to')).toBeNull()
const wrapper = mount(TestComponent, {
attachTo: svg
})

const root = document.getElementById('root')
const rendered = document.getElementById('attach-to')!
expect(wrapper.vm.$el.parentNode).not.toBeNull()
expect(root).not.toBeNull()
expect(rendered).not.toBeNull()
expect(rendered.outerHTML).toBe(outerHTML)
wrapper.unmount()
expect(document.getElementById('attach-to')).toBeNull()
})
it('attaches to a provided CSS selector string', () => {
const div = document.createElement('div')
div.id = 'root'
Expand Down