]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: fix some tests
authorEvan You <yyx990803@gmail.com>
Thu, 8 Nov 2018 17:54:11 +0000 (12:54 -0500)
committerEvan You <yyx990803@gmail.com>
Thu, 8 Nov 2018 17:54:11 +0000 (12:54 -0500)
packages/runtime-core/__tests__/fragment.spec.ts
packages/runtime-core/__tests__/hooks.spec.ts
packages/runtime-core/src/componentProxy.ts
packages/scheduler/src/experimental.ts
packages/scheduler/src/patchNodeOps.ts

index 0096cc771a479efa20f577f469bba404b18647cf..ab069f2d129b682c1e51c8e5a4331e71bee6e83b 100644 (file)
@@ -12,7 +12,8 @@ import {
   nextTick,
   resetOps,
   dumpOps,
-  NodeOpTypes
+  NodeOpTypes,
+  renderInstance
 } from '@vue/runtime-test'
 
 describe('Fragments', () => {
@@ -23,7 +24,7 @@ describe('Fragments', () => {
       }
     }
     const root = nodeOps.createElement('div')
-    await render(h(App), root)
+    await renderInstance(App)
     expect(serialize(root)).toBe(`<div><div>one</div>two</div>`)
     expect(root.children.length).toBe(2)
     expect(root.children[0]).toMatchObject({
index 55f9a4885c35440f095d8deffd68e85f1438a460..e46e5cfa9d2139a27a56816f54c917385295df26 100644 (file)
@@ -1,30 +1,8 @@
-import { withHooks, useState, h, nextTick, useEffect, Component } from '../src'
+import { useState, h, nextTick, useEffect, Component } from '../src'
 import { renderInstance, serialize, triggerEvent } from '@vue/runtime-test'
 
 describe('hooks', () => {
   it('useState', async () => {
-    const Counter = withHooks(() => {
-      const [count, setCount] = useState(0)
-      return h(
-        'div',
-        {
-          onClick: () => {
-            setCount(count + 1)
-          }
-        },
-        count
-      )
-    })
-
-    const counter = await renderInstance(Counter)
-    expect(serialize(counter.$el)).toBe(`<div>0</div>`)
-
-    triggerEvent(counter.$el, 'click')
-    await nextTick()
-    expect(serialize(counter.$el)).toBe(`<div>1</div>`)
-  })
-
-  it('should be usable inside class', async () => {
     class Counter extends Component {
       render() {
         const [count, setCount] = useState(0)
@@ -82,21 +60,23 @@ describe('hooks', () => {
   it('useEffect', async () => {
     let effect = -1
 
-    const Counter = withHooks(() => {
-      const [count, setCount] = useState(0)
-      useEffect(() => {
-        effect = count
-      })
-      return h(
-        'div',
-        {
-          onClick: () => {
-            setCount(count + 1)
-          }
-        },
-        count
-      )
-    })
+    class Counter extends Component {
+      render() {
+        const [count, setCount] = useState(0)
+        useEffect(() => {
+          effect = count
+        })
+        return h(
+          'div',
+          {
+            onClick: () => {
+              setCount(count + 1)
+            }
+          },
+          count
+        )
+      }
+    }
 
     const counter = await renderInstance(Counter)
     expect(effect).toBe(0)
index 633741ac9d85a3065641403479d038cfbf8cc74d..4091b7dc24de194c1ea5eff326e2f6a3c7fd8e0d 100644 (file)
@@ -3,7 +3,7 @@ import { isFunction, isReservedKey } from '@vue/shared'
 import { warn } from './warning'
 import { isRendering } from './componentUtils'
 import { isObservable } from '@vue/observer'
-import { reservedMethods } from '@vue/runtime-dom'
+import { reservedMethods } from './componentOptions'
 
 const bindCache = new WeakMap()
 
index 80a5ccf6b8b3a564cc37f1cc5059b61e8b1c271e..fd2c275949eacfeb4daf3cd356f15c674cf55745 100644 (file)
@@ -171,6 +171,7 @@ function patchJob(job: Job) {
   if (job.ops.length === 0) {
     setCurrentOps(job.ops)
     job()
+    setCurrentOps(null)
     commitQueue.push(job)
   }
 }
index 5077aeacda63cc7b9f4a3c482b73fe37607917fb..e99239af466cddd320953f80c7ce2dfead2549ae 100644 (file)
@@ -5,9 +5,9 @@ import { nodeOps as testNodeOps } from '../../runtime-test/src/nodeOps'
 
 export type Op = [Function, ...any[]]
 
-let currentOps: Op[]
+let currentOps: Op[] | null = null
 
-export function setCurrentOps(ops: Op[]) {
+export function setCurrentOps(ops: Op[] | null) {
   currentOps = ops
 }