test: remove any type from UrlInput test mountComponent helper

- Replace `props: any` with `Record<string, unknown>`
- Use ComponentProps type assertion for type safety
- Refactor tests to check input.element.value instead of internal state
- This tests actual DOM behavior rather than implementation details

Part of Phase 2 - Quick wins (1 instance removed)
This commit is contained in:
Johnpaul
2026-01-21 02:02:27 +01:00
parent 755ad206df
commit 96aa53e5a6

View File

@@ -1,3 +1,5 @@
import type { ComponentProps } from 'vue-component-type-helpers'
import { mount } from '@vue/test-utils'
import PrimeVue from 'primevue/config'
import IconField from 'primevue/iconfield'
@@ -14,13 +16,13 @@ describe('UrlInput', () => {
app.use(PrimeVue)
})
const mountComponent = (props: any, options = {}) => {
const mountComponent = (props: Record<string, unknown>, options = {}) => {
return mount(UrlInput, {
global: {
plugins: [PrimeVue],
components: { IconField, InputIcon, InputText }
},
props,
props: props as unknown as ComponentProps<typeof UrlInput>,
...options
})
}
@@ -169,25 +171,25 @@ describe('UrlInput', () => {
await input.setValue(' https://leading-space.com')
await input.trigger('input')
await nextTick()
expect(wrapper.vm.internalValue).toBe('https://leading-space.com')
expect(input.element.value).toBe('https://leading-space.com')
// Test trailing whitespace
await input.setValue('https://trailing-space.com ')
await input.trigger('input')
await nextTick()
expect(wrapper.vm.internalValue).toBe('https://trailing-space.com')
expect(input.element.value).toBe('https://trailing-space.com')
// Test both leading and trailing whitespace
await input.setValue(' https://both-spaces.com ')
await input.trigger('input')
await nextTick()
expect(wrapper.vm.internalValue).toBe('https://both-spaces.com')
expect(input.element.value).toBe('https://both-spaces.com')
// Test whitespace in the middle of the URL
await input.setValue('https:// middle-space.com')
await input.trigger('input')
await nextTick()
expect(wrapper.vm.internalValue).toBe('https://middle-space.com')
expect(input.element.value).toBe('https://middle-space.com')
})
it('trims whitespace when value set externally', async () => {
@@ -196,15 +198,17 @@ describe('UrlInput', () => {
placeholder: 'Enter URL'
})
const input = wrapper.find('input')
// Check initial value is trimmed
expect(wrapper.vm.internalValue).toBe('https://initial-value.com')
expect(input.element.value).toBe('https://initial-value.com')
// Update props with whitespace
await wrapper.setProps({ modelValue: ' https://updated-value.com ' })
await nextTick()
// Check updated value is trimmed
expect(wrapper.vm.internalValue).toBe('https://updated-value.com')
expect(input.element.value).toBe('https://updated-value.com')
})
})
})