Skip to content

Commit

Permalink
fix: update attachTo type to support SVGElement (vuejs#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
taku-y-9308 authored and nazarepiedady committed Jul 18, 2024
1 parent bf00c4c commit 92a32bc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
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

0 comments on commit 92a32bc

Please sign in to comment.