Просмотр исходного кода

test(runtime-vapor): add template tests

[skip-release]
三咲智子 Kevin Deng 2 лет назад
Родитель
Сommit
0e57653183

+ 3 - 3
packages/runtime-vapor/__tests__/dom/patchProp.spec.ts

@@ -1,14 +1,14 @@
 import { NOOP } from '@vue/shared'
 import { NOOP } from '@vue/shared'
 import {
 import {
+  setDynamicProp as _setDynamicProp,
   setAttr,
   setAttr,
   setClass,
   setClass,
   setDOMProp,
   setDOMProp,
   setDynamicProps,
   setDynamicProps,
   setHtml,
   setHtml,
-  setStyle,
   setText,
   setText,
-} from '../../src'
-import { setDynamicProp as _setDynamicProp } from '../../src/dom/prop'
+} from '../../src/dom/prop'
+import { setStyle } from '../../src/dom/style'
 import {
 import {
   createComponentInstance,
   createComponentInstance,
   setCurrentInstance,
   setCurrentInstance,

+ 36 - 0
packages/runtime-vapor/__tests__/dom/template.spec.ts

@@ -0,0 +1,36 @@
+import { children, next, template } from '../../src/dom/template'
+
+describe('api: template', () => {
+  test('create element', () => {
+    const t = template('<div>')
+    const root = t()
+    expect(root).toBeInstanceOf(HTMLDivElement)
+
+    const root2 = t()
+    expect(root2).toBeInstanceOf(HTMLDivElement)
+    expect(root2).not.toBe(root)
+  })
+
+  test('children', () => {
+    const t = template('<div><span><b>nested</b></span><p></p></div>')
+    const root = t()
+    const span = children(root, 0)
+    const b = children(span, 0)
+    const p = children(root, 1)
+    expect(span).toBe(root.firstChild)
+    expect(b).toBe(root.firstChild!.firstChild)
+    expect(p).toBe(root.firstChild!.nextSibling)
+  })
+
+  test('next', () => {
+    const t = template('<div><span></span><b></b><p></p></div>')
+    const root = t()
+    const span = children(root, 0)
+    const b = next(span, 1)
+
+    expect(span).toBe(root.childNodes[0])
+    expect(b).toBe(root.childNodes[1])
+    expect(next(span, 2)).toBe(root.childNodes[2])
+    expect(next(b, 1)).toBe(root.childNodes[2])
+  })
+})

+ 0 - 13
packages/runtime-vapor/__tests__/template.spec.ts

@@ -1,13 +0,0 @@
-import { template } from '../src'
-
-describe('api: template', () => {
-  test('create element', () => {
-    const t = template('<div>')
-    const root = t()
-    expect(root).toBeInstanceOf(HTMLDivElement)
-
-    const root2 = t()
-    expect(root2).toBeInstanceOf(HTMLDivElement)
-    expect(root2).not.toBe(root)
-  })
-})