Prechádzať zdrojové kódy

chore: fix unit tests

Evan You 3 rokov pred
rodič
commit
b4c511da8f

+ 7 - 2
src/core/observer/index.ts

@@ -19,6 +19,8 @@ import { isReadonly, isRef } from '../../v3'
 
 const arrayKeys = Object.getOwnPropertyNames(arrayMethods)
 
+const NO_INIITIAL_VALUE = {}
+
 /**
  * In some cases we may want to disable observation inside a component's
  * update computation.
@@ -67,7 +69,7 @@ export class Observer {
     const keys = Object.keys(obj)
     for (let i = 0; i < keys.length; i++) {
       const key = keys[i]
-      defineReactive(obj, key, obj[key], undefined, shallow)
+      defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow)
     }
   }
 
@@ -149,7 +151,10 @@ export function defineReactive(
   // cater for pre-defined getter/setters
   const getter = property && property.get
   const setter = property && property.set
-  if ((!getter || setter) && arguments.length === 2) {
+  if (
+    (!getter || setter) &&
+    (val === NO_INIITIAL_VALUE || arguments.length === 2)
+  ) {
     val = obj[key]
   }
 

+ 1 - 0
test/unit/features/directives/class.spec.ts

@@ -1,4 +1,5 @@
 import Vue from 'vue'
+import { isFunction } from 'core/util'
 
 function assertClass(assertions, done) {
   const vm = new Vue({

+ 1 - 1
test/unit/modules/compiler/codegen.spec.ts

@@ -1,7 +1,7 @@
 import { parse } from 'compiler/parser/index'
 import { optimize } from 'compiler/optimizer'
 import { generate } from 'compiler/codegen'
-import { isObject, extend } from 'shared/util'
+import { isObject, isFunction, extend } from 'shared/util'
 import { isReservedTag } from 'web/util/index'
 import { baseOptions } from 'web/compiler/options'