feat(Input): use defineModel (#61)

This commit is contained in:
Romain Hamel
2024-03-22 17:14:57 +01:00
committed by GitHub
parent cd1073d938
commit 091f8e91c4
2 changed files with 43 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest'
import { describe, it, expect, test } from 'vitest'
import Input, { type InputProps } from '../../src/runtime/components/Input.vue'
import ComponentRender from '../component-render'
import { mountSuspended } from '@nuxt/test-utils/runtime'
describe('Input', () => {
it.each([
@@ -30,4 +31,36 @@ describe('Input', () => {
const html = await ComponentRender(nameOrHtml, options, Input)
expect(html).toMatchSnapshot()
})
// See: https://github.com/nuxt/test-utils/issues/572
it.skip.each([
['with .trim modifier', { props: { modelModifiers: { trim: true } } }, { input: 'input ', expected: 'input' } ],
['with .number modifier', { props: { modelModifiers: { number: true } } }, { input: '42', expected: 42 } ],
['with .lazy modifier', { props: { modelModifiers: { lazy: true } } }, { input: 'input', expected: 'input' } ]
])('%s works', async (_nameOrHtml: string, options: { props?: any, slots?: any }, spec: { input: any, expected: any }) => {
const wrapper = await mountSuspended(Input, {
...options
})
const input = wrapper.find('input')
await input.setValue(spec.input)
expect(wrapper.emitted()).toMatchObject({ 'update:modelValue': [[spec.expected]] })
})
// See: https://github.com/nuxt/test-utils/issues/572
test.skip('with .lazy modifier updates on change only', async () => {
const wrapper = await mountSuspended(Input, {
props: {
modelModifiers: { lazy: true }
}
})
const input = wrapper.find('input')
await input.trigger('update')
expect(wrapper.emitted()).toMatchObject({ })
await input.trigger('change')
expect(wrapper.emitted()).toMatchObject({ 'update:modelValue': [['']] })
})
})