Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/app-vitest-full/tests/nuxt/mount-suspended.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,30 @@ describe.each(Object.entries(formats))(`%s`, (name, component) => {
expect(wrapper.html()).toEqual(`
<div>
<h1>${name}</h1><pre>updated title</pre><pre>XHello nuxt-vitest</pre><span>hello</span><span>nuxt</span><span>vitest</span><span>myObjProp: {}</span>
</div>
`.trim())
})

it('can be updated to null with setProps', async () => {
await wrapper.setProps({
myProp: 'updated title',
myObjProp: null,
})
expect(wrapper.html()).toEqual(`
<div>
<h1>${name}</h1><pre>updated title</pre><pre>XHello nuxt-vitest</pre><span>hello</span><span>nuxt</span><span>vitest</span><span>myObjProp: null</span>
</div>
`.trim())
})

it('can be updated to undefined with setProps', async () => {
await wrapper.setProps({
myProp: 'updated title',
myObjProp: undefined,
})
expect(wrapper.html()).toEqual(`
<div>
<h1>${name}</h1><pre>updated title</pre><pre>XHello nuxt-vitest</pre><span>hello</span><span>nuxt</span><span>vitest</span><span>myObjProp: {}</span>
</div>
`.trim())
})
Expand Down
9 changes: 2 additions & 7 deletions src/runtime-utils/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils'
import type { ComponentMountingOptions } from '@vue/test-utils'
import { Suspense, h, isReadonly, nextTick, reactive, unref, getCurrentInstance } from 'vue'
import type { DefineComponent, SetupContext } from 'vue'
import { defu, createDefu } from 'defu'
import { defu } from 'defu'
import type { RouteLocationRaw } from 'vue-router'

import { RouterLink } from './components/RouterLink'
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function mountSuspended<T>(
setup: setup ? (props: Record<string, unknown>) => wrappedSetup(props, setupContext) : undefined,
}

return () => h(clonedComponent, { ...customMerge(setProps, props) as typeof props, ...attrs }, slots)
return () => h(clonedComponent, { ...props, ...setProps, ...attrs }, slots)
},
}),
},
Expand Down Expand Up @@ -201,11 +201,6 @@ interface AugmentedVueInstance {
__setProps?: (props: Record<string, unknown>) => void
}

const customMerge = createDefu((obj, key, value) => {
obj[key] = value
return true
})

function cloneProps(props: Record<string, unknown>) {
const newProps = reactive<Record<string, unknown>>({})
for (const key in props) {
Expand Down
Loading