32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { h } from 'vue'
|
|
import { mount } from '@vue/test-utils'
|
|
import { RadioGroup, RadioGroupItem } from '../src/lib'
|
|
|
|
describe('RadioGroup', () => {
|
|
it('marks the item matching modelValue as checked', () => {
|
|
const wrapper = mount(RadioGroup, {
|
|
props: { modelValue: 'hades' },
|
|
slots: {
|
|
default: () => [
|
|
h(RadioGroupItem, { value: 'apollo' }),
|
|
h(RadioGroupItem, { value: 'hades' }),
|
|
],
|
|
},
|
|
})
|
|
const items = wrapper.findAllComponents(RadioGroupItem)
|
|
expect(items[0]?.get('button').attributes('data-state')).toBe('unchecked')
|
|
expect(items[1]?.get('button').attributes('data-state')).toBe('checked')
|
|
})
|
|
|
|
it('emits update:modelValue when an item is selected', async () => {
|
|
const wrapper = mount(RadioGroup, {
|
|
props: { modelValue: 'apollo' },
|
|
slots: {
|
|
default: () => [h(RadioGroupItem, { value: 'hades' })],
|
|
},
|
|
})
|
|
await wrapper.findComponent(RadioGroupItem).get('button').trigger('click')
|
|
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual(['hades'])
|
|
})
|
|
})
|