Browse Source

allow nodes that are not imported yet (fixes #1252)

master
Ulrich-Matthias Schäfer 9 months ago
parent
commit
9ed85cff5e
2 changed files with 16 additions and 2 deletions
  1. 13
    0
      spec/spec/utils/adopter.js
  2. 3
    2
      src/utils/adopter.js

+ 13
- 0
spec/spec/utils/adopter.js View File

import { mockAdopt, assignNewId, adopt } from '../../../src/utils/adopter.js' import { mockAdopt, assignNewId, adopt } from '../../../src/utils/adopter.js'
import { buildFixtures } from '../../helpers.js' import { buildFixtures } from '../../helpers.js'
import { globals, getWindow } from '../../../src/utils/window.js' import { globals, getWindow } from '../../../src/utils/window.js'
import { svg } from '../../../src/modules/core/namespaces.js'


const { any, createSpy, objectContaining } = jasmine const { any, createSpy, objectContaining } = jasmine


// jasmine chucks on this when using the node directly // jasmine chucks on this when using the node directly
expect(node.outerHTML).toBe(div.outerHTML) expect(node.outerHTML).toBe(div.outerHTML)
}) })

it('gracefully handles nodes that are not yet imported into the document', () => {
const otherDoc = globals.document.implementation.createDocument(
svg,
'svg'
)
const rect = otherDoc.createElementNS(svg, 'rect')

const node = nodeOrNew('rect', rect)

expect(node).toEqual(rect)
})
}) })


describe('register()/getClass()', () => { describe('register()/getClass()', () => {

+ 3
- 2
src/utils/adopter.js View File



export function nodeOrNew(name, node) { export function nodeOrNew(name, node) {
return node && return node &&
node.ownerDocument &&
node instanceof node.ownerDocument.defaultView.Node
(node instanceof globals.window.Node ||
(node.ownerDocument &&
node instanceof node.ownerDocument.defaultView.Node))
? node ? node
: create(name) : create(name)
} }

Loading…
Cancel
Save