]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: compat test coverage
authorEvan You <yyx990803@gmail.com>
Fri, 30 Apr 2021 22:05:03 +0000 (18:05 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 30 Apr 2021 22:05:03 +0000 (18:05 -0400)
packages/runtime-core/src/compat/renderFn.ts
packages/vue-compat/__tests__/componentAsync.spec.ts
packages/vue-compat/__tests__/global.spec.ts
packages/vue-compat/__tests__/renderFn.spec.ts

index ffbd34e7667e843d5f8763ae64320f2a4fa3fc1e..ba67cd36636de4a8e495bac8a39c454bb6218869 100644 (file)
@@ -113,7 +113,7 @@ export function compatH(
 ): VNode
 export function compatH(
   type: string | Component,
-  props?: LegacyVNodeProps,
+  props?: Data & LegacyVNodeProps,
   children?: LegacyVNodeChildren
 ): VNode
 
@@ -190,16 +190,12 @@ function convertLegacyProps(
     } else if (key === 'on' || key === 'nativeOn') {
       const listeners = legacyProps[key]
       for (const event in listeners) {
-        const handlerKey = convertLegacyEventKey(event)
+        let handlerKey = convertLegacyEventKey(event)
+        if (key === 'nativeOn') handlerKey += `Native`
         const existing = converted[handlerKey]
         const incoming = listeners[event]
         if (existing !== incoming) {
           if (existing) {
-            // for the rare case where the same handler is attached
-            // twice with/without .native modifier...
-            if (key === 'nativeOn' && String(existing) === String(incoming)) {
-              continue
-            }
             converted[handlerKey] = [].concat(existing as any, incoming as any)
           } else {
             converted[handlerKey] = incoming
@@ -307,6 +303,7 @@ function convertLegacySlots(vnode: VNode): VNode {
 }
 
 export function defineLegacyVNodeProperties(vnode: VNode) {
+  /* istanbul ignore if */
   if (
     isCompatEnabled(
       DeprecationTypes.RENDER_FUNCTION,
index c7d2a789962f1108daf403815baa449fc5ccc579..9e7316a6ce4c5e9d4556517790c8f40fc18f64e1 100644 (file)
@@ -59,4 +59,24 @@ describe('COMPONENT_ASYNC', () => {
       )
     ).toHaveBeenWarned()
   })
+
+  test('object syntax', async () => {
+    const comp = () => ({
+      component: Promise.resolve({ template: 'foo' })
+    })
+
+    const vm = new Vue({
+      template: `<div><comp/></div>`,
+      components: { comp }
+    }).$mount()
+    expect(vm.$el.innerHTML).toBe(`<!---->`)
+    await timeout(0)
+    expect(vm.$el.innerHTML).toBe(`foo`)
+
+    expect(
+      (deprecationData[DeprecationTypes.COMPONENT_ASYNC].message as Function)(
+        comp
+      )
+    ).toHaveBeenWarned()
+  })
 })
index 8b8b066e1ba18ff03ba92aef864c6037a9a9a974..ad3619dd64111ccf5a9ee0c33319c1518c8618a3 100644 (file)
@@ -1,5 +1,6 @@
 import Vue from '@vue/compat'
 import { effect, isReactive } from '@vue/reactivity'
+import { nextTick } from '@vue/runtime-core'
 import {
   DeprecationTypes,
   deprecationData,
@@ -333,4 +334,50 @@ describe('GLOBAL_PRIVATE_UTIL', () => {
       deprecationData[DeprecationTypes.GLOBAL_PRIVATE_UTIL].message
     ).toHaveBeenWarned()
   })
+
+  test('defineReactive on instance', async () => {
+    const vm = new Vue({
+      beforeCreate() {
+        // @ts-ignore
+        Vue.util.defineReactive(this, 'foo', 1)
+      },
+      template: `<div>{{ foo }}</div>`
+    }).$mount() as any
+    expect(vm.$el.textContent).toBe('1')
+    vm.foo = 2
+    await nextTick()
+    expect(vm.$el.textContent).toBe('2')
+  })
+
+  test('defineReactive with object value', () => {
+    const obj: any = {}
+    const val = { a: 1 }
+    // @ts-ignore
+    Vue.util.defineReactive(obj, 'foo', val)
+
+    let n
+    effect(() => {
+      n = obj.foo.a
+    })
+    expect(n).toBe(1)
+    // mutating original
+    val.a++
+    expect(n).toBe(2)
+  })
+
+  test('defineReactive with array value', () => {
+    const obj: any = {}
+    const val = [1]
+    // @ts-ignore
+    Vue.util.defineReactive(obj, 'foo', val)
+
+    let n
+    effect(() => {
+      n = obj.foo.length
+    })
+    expect(n).toBe(1)
+    // mutating original
+    val.push(2)
+    expect(n).toBe(2)
+  })
 })
index 00ad4c239acf780a41ca723cce033878414136a6..27b320e71b71cd33f27c4a7a3f09307692fe454d 100644 (file)
@@ -123,9 +123,29 @@ describe('compat: render function', () => {
       })
     ).toMatchObject({
       props: {
-        onClick: fn, // should dedupe
+        onClick: fn,
+        onClickNative: fn,
         onFooBar: fn,
-        'onBar-baz': fn
+        'onBar-bazNative': fn
+      }
+    })
+  })
+
+  test('v2 legacy event prefixes', () => {
+    const fn = () => {}
+    expect(
+      h('div', {
+        on: {
+          '&click': fn,
+          '~keyup': fn,
+          '!touchend': fn
+        }
+      })
+    ).toMatchObject({
+      props: {
+        onClickPassive: fn,
+        onKeyupOnce: fn,
+        onTouchendCapture: fn
       }
     })
   })