Forráskód Böngészése

test: fix test case broken by b93f264

Evan You 2 éve
szülő
commit
a7cf74277e

+ 5 - 3
packages/runtime-core/__tests__/componentProps.spec.ts

@@ -11,15 +11,17 @@ import {
   getCurrentInstance,
   h,
   inject,
+  nextTick,
   nodeOps,
   provide,
   ref,
   render,
   serializeInner,
+  toRaw,
   toRefs,
   watch,
 } from '@vue/runtime-test'
-import { render as domRender, nextTick } from 'vue'
+import { render as domRender } from 'vue'
 
 describe('component props', () => {
   test('stateful', () => {
@@ -127,12 +129,12 @@ describe('component props', () => {
     render(h(Comp, { foo: 1 }), root)
     expect(props).toEqual({ foo: 1 })
     expect(attrs).toEqual({ foo: 1 })
-    expect(props).toBe(attrs)
+    expect(toRaw(props)).toBe(attrs)
 
     render(h(Comp, { bar: 2 }), root)
     expect(props).toEqual({ bar: 2 })
     expect(attrs).toEqual({ bar: 2 })
-    expect(props).toBe(attrs)
+    expect(toRaw(props)).toBe(attrs)
   })
 
   test('boolean casting', () => {

+ 7 - 4
packages/runtime-core/src/componentRenderUtils.ts

@@ -55,12 +55,12 @@ export function renderComponentRoot(
     emit,
     render,
     renderCache,
+    props,
     data,
     setupState,
     ctx,
     inheritAttrs,
   } = instance
-  const props = __DEV__ ? shallowReadonly(instance.props) : instance.props
   const prev = setCurrentRenderingInstance(instance)
 
   let result
@@ -94,7 +94,7 @@ export function renderComponentRoot(
           thisProxy,
           proxyToUse!,
           renderCache,
-          props,
+          __DEV__ ? shallowReadonly(props) : props,
           setupState,
           data,
           ctx,
@@ -111,7 +111,7 @@ export function renderComponentRoot(
       result = normalizeVNode(
         render.length > 1
           ? render(
-              props,
+              __DEV__ ? shallowReadonly(props) : props,
               __DEV__
                 ? {
                     get attrs() {
@@ -123,7 +123,10 @@ export function renderComponentRoot(
                   }
                 : { attrs, slots, emit },
             )
-          : render(props, null as any /* we know it doesn't need it */),
+          : render(
+              __DEV__ ? shallowReadonly(props) : props,
+              null as any /* we know it doesn't need it */,
+            ),
       )
       fallthroughAttrs = Component.props
         ? attrs