test: fix test case broken by b93f264

This commit is contained in:
Evan You 2024-04-22 21:05:00 +08:00
parent b93f264647
commit a7cf74277e
No known key found for this signature in database
GPG Key ID: B9D421896CA450FB
2 changed files with 12 additions and 7 deletions

View File

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

View File

@ -55,12 +55,12 @@ export function renderComponentRoot(
emit, emit,
render, render,
renderCache, renderCache,
props,
data, data,
setupState, setupState,
ctx, ctx,
inheritAttrs, inheritAttrs,
} = instance } = instance
const props = __DEV__ ? shallowReadonly(instance.props) : instance.props
const prev = setCurrentRenderingInstance(instance) const prev = setCurrentRenderingInstance(instance)
let result let result
@ -94,7 +94,7 @@ export function renderComponentRoot(
thisProxy, thisProxy,
proxyToUse!, proxyToUse!,
renderCache, renderCache,
props, __DEV__ ? shallowReadonly(props) : props,
setupState, setupState,
data, data,
ctx, ctx,
@ -111,7 +111,7 @@ export function renderComponentRoot(
result = normalizeVNode( result = normalizeVNode(
render.length > 1 render.length > 1
? render( ? render(
props, __DEV__ ? shallowReadonly(props) : props,
__DEV__ __DEV__
? { ? {
get attrs() { get attrs() {
@ -123,7 +123,10 @@ export function renderComponentRoot(
} }
: { attrs, slots, emit }, : { 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 fallthroughAttrs = Component.props
? attrs ? attrs