2024-01-23 10:22:45 +00:00
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { ComponentOptions } from 'vue'
|
|
|
|
import { defineComponent, h, toDisplayString, useAttrs } from 'vue'
|
|
|
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
|
|
import { createClientOnly } from '../../packages/nuxt/src/app/components/client-only'
|
|
|
|
|
|
|
|
const Client = defineComponent({
|
|
|
|
name: 'TestClient',
|
|
|
|
setup () {
|
|
|
|
const attrs = useAttrs()
|
|
|
|
return () => h('div', {}, toDisplayString(attrs))
|
2024-04-05 18:08:32 +00:00
|
|
|
},
|
2024-01-23 10:22:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('createClient attribute inheritance', () => {
|
|
|
|
it('should retrieve attributes with useAttrs()', async () => {
|
|
|
|
const wrapper = await mountSuspended(createClientOnly(Client as ComponentOptions), {
|
|
|
|
attrs: {
|
2024-04-05 18:08:32 +00:00
|
|
|
id: 'client',
|
|
|
|
},
|
2024-01-23 10:22:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.html()).toMatchInlineSnapshot(`
|
|
|
|
"<div id="client">{
|
|
|
|
"id": "client"
|
|
|
|
}</div>"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
})
|