vue3-yuanma/packages/runtime-dom/__tests__/nodeOps.spec.ts
dependabot[bot] 305883a12f
build(deps-dev): bump typescript from 4.3.5 to 4.4.2 (#4482)
* build(deps-dev): bump typescript from 4.3.5 to 4.4.2

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.3.5 to 4.4.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.3.5...v4.4.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps-dev): bump typescript from 4.3.5 to 4.4.2

* test: fix nodeOps types

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Carlos Rodrigues <carlos@hypermob.co.uk>
Co-authored-by: Evan You <yyx990803@gmail.com>
2021-09-02 09:53:57 -04:00

87 lines
3.2 KiB
TypeScript

import { nodeOps, svgNS } from '../src/nodeOps'
describe('runtime-dom: node-ops', () => {
test('the _value property should be cloned', () => {
const el = nodeOps.createElement('input') as HTMLDivElement & {
_value: any
}
el._value = 1
const cloned = nodeOps.cloneNode!(el) as HTMLDivElement & { _value: any }
expect(cloned._value).toBe(1)
})
test("the <select>'s multiple attr should be set in createElement", () => {
const el = nodeOps.createElement('select', false, undefined, {
multiple: ''
}) as HTMLSelectElement
const option1 = nodeOps.createElement('option') as HTMLOptionElement
const option2 = nodeOps.createElement('option') as HTMLOptionElement
option1.selected = true
option2.selected = true
nodeOps.insert(option1, el)
nodeOps.insert(option2, el)
expect(el.multiple).toBe(true)
expect(option1.selected).toBe(true)
expect(option2.selected).toBe(true)
})
describe('insertStaticContent', () => {
test('fresh insertion', () => {
const content = `<div>one</div><div>two</div>three`
const parent = document.createElement('div')
const nodes = nodeOps.insertStaticContent!(content, parent, null, false)
expect(parent.innerHTML).toBe(content)
expect(nodes[0]).toBe(parent.firstChild)
expect(nodes[1]).toBe(parent.lastChild)
})
test('fresh insertion with anchor', () => {
const content = `<div>one</div><div>two</div>three`
const existing = `<div>existing</div>`
const parent = document.createElement('div')
parent.innerHTML = existing
const anchor = parent.firstChild
const nodes = nodeOps.insertStaticContent!(content, parent, anchor, false)
expect(parent.innerHTML).toBe(content + existing)
expect(nodes[0]).toBe(parent.firstChild)
expect(nodes[1]).toBe(parent.childNodes[parent.childNodes.length - 2])
})
test('fresh insertion as svg', () => {
const content = `<text>hello</text><circle cx="100" cy="100" r="80"></circle>`
const parent = document.createElementNS(svgNS, 'svg')
const [first, last] = nodeOps.insertStaticContent!(
content,
parent,
null,
true
)
expect(parent.innerHTML).toBe(content)
expect(first).toBe(parent.firstChild)
expect(last).toBe(parent.lastChild)
expect((first as Element).namespaceURI).toMatch('svg')
expect((last as Element).namespaceURI).toMatch('svg')
})
test('fresh insertion as svg, with anchor', () => {
const content = `<text>hello</text><circle cx="100" cy="100" r="80"></circle>`
const existing = `<path></path>`
const parent = document.createElementNS(svgNS, 'svg')
parent.innerHTML = existing
const anchor = parent.firstChild
const [first, last] = nodeOps.insertStaticContent!(
content,
parent,
anchor,
true
)
expect(parent.innerHTML).toBe(content + existing)
expect(first).toBe(parent.firstChild)
expect(last).toBe(parent.childNodes[parent.childNodes.length - 2])
expect((first as Element).namespaceURI).toMatch('svg')
expect((last as Element).namespaceURI).toMatch('svg')
})
})
})