From bd1b06f1cc29a8a161a0de100cb292a14e541be1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 8 Nov 2018 12:54:11 -0500 Subject: [PATCH] test: fix some tests --- .../runtime-core/__tests__/fragment.spec.ts | 5 +- packages/runtime-core/__tests__/hooks.spec.ts | 56 ++++++------------- packages/runtime-core/src/componentProxy.ts | 2 +- packages/scheduler/src/experimental.ts | 1 + packages/scheduler/src/patchNodeOps.ts | 4 +- 5 files changed, 25 insertions(+), 43 deletions(-) diff --git a/packages/runtime-core/__tests__/fragment.spec.ts b/packages/runtime-core/__tests__/fragment.spec.ts index 0096cc77..ab069f2d 100644 --- a/packages/runtime-core/__tests__/fragment.spec.ts +++ b/packages/runtime-core/__tests__/fragment.spec.ts @@ -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(`
one
two
`) expect(root.children.length).toBe(2) expect(root.children[0]).toMatchObject({ diff --git a/packages/runtime-core/__tests__/hooks.spec.ts b/packages/runtime-core/__tests__/hooks.spec.ts index 55f9a488..e46e5cfa 100644 --- a/packages/runtime-core/__tests__/hooks.spec.ts +++ b/packages/runtime-core/__tests__/hooks.spec.ts @@ -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(`
0
`) - - triggerEvent(counter.$el, 'click') - await nextTick() - expect(serialize(counter.$el)).toBe(`
1
`) - }) - - 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) diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 633741ac..4091b7dc 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -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() diff --git a/packages/scheduler/src/experimental.ts b/packages/scheduler/src/experimental.ts index 80a5ccf6..fd2c2759 100644 --- a/packages/scheduler/src/experimental.ts +++ b/packages/scheduler/src/experimental.ts @@ -171,6 +171,7 @@ function patchJob(job: Job) { if (job.ops.length === 0) { setCurrentOps(job.ops) job() + setCurrentOps(null) commitQueue.push(job) } } diff --git a/packages/scheduler/src/patchNodeOps.ts b/packages/scheduler/src/patchNodeOps.ts index 5077aeac..e99239af 100644 --- a/packages/scheduler/src/patchNodeOps.ts +++ b/packages/scheduler/src/patchNodeOps.ts @@ -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 }