fix(Table): handle reactive columns (#4412)

This commit is contained in:
VALERIY SINEVICH
2025-06-30 16:20:35 +03:00
committed by GitHub
parent fb9e7bb856
commit 4ce654076c
2 changed files with 48 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
import { h } from 'vue'
import { h, ref, computed } from 'vue'
import { describe, it, expect } from 'vitest'
import { flushPromises } from '@vue/test-utils'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { UCheckbox, UButton, UBadge, UDropdownMenu } from '#components'
import Table, { type TableProps, type TableSlots, type TableColumn } from '../../src/runtime/components/Table.vue'
import ComponentRender from '../component-render'
@@ -168,4 +170,46 @@ describe('Table', () => {
const html = await ComponentRender(nameOrHtml, options, Table)
expect(html).toMatchSnapshot()
})
it('reactive columns', async () => {
const wrapper = await mountSuspended({
components: { Table },
setup() {
const filter = ref<1 | 2>(1)
const columns = computed<TableColumn<typeof data[number]>[]>(() => [
{
accessorKey: 'id'
},
...(filter.value === 2
? [
{
accessorKey: 'amount',
header: () => h('div', { ['data-test-th']: 'amount' }, 'Amount')
} satisfies TableColumn<typeof data[number]>
]
: [])
])
function onClick() {
filter.value = 2
}
return { data, columns, onClick }
},
template: `
<div>
<button @click="onClick">Change filter</button>
<Table :data :columns />
</div>
`
})
expect(wrapper.find('[data-test-th="amount"]').exists()).toBeFalsy()
wrapper.find('button').trigger('click')
await flushPromises()
expect(wrapper.find('[data-test-th="amount"]').exists()).toBeTruthy()
})
})