Nychthemeron/packages/library/tests/RadioGroup.spec.ts
Matthew L McPeak 38674be217
All checks were successful
ci / build (push) Successful in 35s
ci / publish (push) Successful in 11s
ci / publish-docs (push) Successful in 1m4s
Inital Commit
2026-07-15 20:47:53 -04:00

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'])
})
})