Skip to content

Commit 290e4ce

Browse files
committed
test: lint
1 parent 9993b67 commit 290e4ce

File tree

6 files changed

+40
-43
lines changed

6 files changed

+40
-43
lines changed

test/component-render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import path from 'node:path'
12
import { mountSuspended } from '@nuxt/test-utils/runtime'
2-
import path from 'path'
33

44
export default async function (nameOrHtml: string, options: any, component: any) {
55
let html: string

test/components/Checkbox.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from 'vitest'
2+
import { defu } from 'defu'
23
import Checkbox, { type CheckboxProps } from '../../src/runtime/components/Checkbox.vue'
34
import ComponentRender from '../component-render'
4-
import { defu } from 'defu'
55

66
describe('Checkbox', () => {
77
it.each([
@@ -16,15 +16,14 @@ describe('Checkbox', () => {
1616
['with indeterminate', { props: { indeterminate: true } }],
1717
['with help', { props: { label: 'Label', help: 'Help' } }],
1818
['with required', { props: { label: 'Label', required: true } }],
19-
['with custom color', { props: { label: 'Label', color: 'red' } }],
19+
['with custom color', { props: { label: 'Label', color: 'red' as const } }],
2020
['with size 2xs', { props: { size: '2xs' as const } }],
2121
['with size xs', { props: { size: 'xs' as const } }],
2222
['with size sm', { props: { size: 'sm' as const } }],
2323
['with size md', { props: { size: 'md' as const } }],
2424
['with size lg', { props: { size: 'lg' as const } }],
2525
['with size xl', { props: { size: 'xl' as const } }]
26-
// @ts-ignore
27-
])('renders %s correctly', async (nameOrHtml: string, options: { props?: CheckboxProps }) => {
26+
])('renders %s correctly', async (nameOrHtml: string, options: { props?: CheckboxProps, slots?: any }) => {
2827
const html = await ComponentRender(nameOrHtml, defu(options, { props: { id: 42 } }), Checkbox)
2928
expect(html).toMatchSnapshot()
3029
})

test/components/Form.spec.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { reactive, ref, nextTick } from 'vue'
22
import { describe, it, expect, test, beforeEach, vi } from 'vitest'
3+
import type { DOMWrapper, VueWrapper } from '@vue/test-utils'
4+
import { flushPromises } from '@vue/test-utils'
5+
import { mountSuspended } from '@nuxt/test-utils/runtime'
6+
import { z } from 'zod'
7+
import * as yup from 'yup'
8+
import Joi from 'joi'
9+
import * as valibot from 'valibot'
10+
import ComponentRender from '../component-render'
311
import type { FormProps } from '../../src/runtime/components/Form.vue'
412
import {
513
UForm,
@@ -15,38 +23,31 @@ import {
1523
// UToggle,
1624
// URange
1725
} from '#components'
18-
import { DOMWrapper, flushPromises, VueWrapper } from '@vue/test-utils'
19-
import ComponentRender from '../component-render'
20-
21-
import { mountSuspended } from '@nuxt/test-utils/runtime'
22-
import { z } from 'zod'
23-
import * as yup from 'yup'
24-
import Joi from 'joi'
25-
import * as valibot from 'valibot'
2626

27-
async function triggerEvent (
27+
async function triggerEvent(
2828
el: DOMWrapper<Element> | VueWrapper<any, any>,
2929
event: string
3030
) {
3131
el.trigger(event)
3232
return flushPromises()
3333
}
3434

35-
async function setValue (
35+
async function setValue(
3636
el: DOMWrapper<Element> | VueWrapper<any, any>,
3737
value: any
3838
) {
3939
el.setValue(value)
4040
return flushPromises()
4141
}
4242

43-
async function renderForm (options: {
43+
async function renderForm(options: {
4444
props: Partial<FormProps<any>>
4545
slotVars?: object
4646
slotComponents?: any
4747
slotTemplate: string
4848
}) {
4949
const state = reactive({})
50+
5051
return await mountSuspended(UForm, {
5152
props: {
5253
id: 42,
@@ -55,8 +56,8 @@ async function renderForm (options: {
5556
},
5657
slots: {
5758
default: {
58-
// @ts-ignore
59-
setup () {
59+
// @ts-expect-error setup does not exist on type
60+
setup() {
6061
return { state, ...options.slotVars }
6162
},
6263
components: {
@@ -112,7 +113,7 @@ describe('Form', () => {
112113
}
113114
],
114115
['custom', {
115-
async validate (state: any) {
116+
async validate(state: any) {
116117
const errs = []
117118
if (!state.email)
118119
errs.push({ name: 'email', message: 'Email is required' })
@@ -152,7 +153,7 @@ describe('Form', () => {
152153

153154
await triggerEvent(form, 'submit.prevent')
154155

155-
// @ts-ignore
156+
// @ts-expect-error object is possibly undefined
156157
expect(wrapper.emitted('error')[0][0].errors).toMatchObject([
157158
{
158159
id: 'password',
@@ -181,7 +182,7 @@ describe('Form', () => {
181182
const wrapper = await renderForm({
182183
props: {
183184
validateOn: ['blur'],
184-
async validate (state: any) {
185+
async validate(state: any) {
185186
if (!state.value)
186187
return [{ name: 'value', message: 'Error message' }]
187188
return []
@@ -216,7 +217,7 @@ describe('Form', () => {
216217
const wrapper = await renderForm({
217218
props: {
218219
validateOn: ['change'],
219-
async validate (state: any) {
220+
async validate(state: any) {
220221
if (!state.value)
221222
return [{ name: 'value', message: 'Error message' }]
222223
return []
@@ -416,7 +417,7 @@ describe('Form', () => {
416417
const wrapper = await renderForm({
417418
props: {
418419
validateOn: ['input', 'blur'],
419-
async validate (state: any) {
420+
async validate(state: any) {
420421
if (!state.value)
421422
return [{ name: 'value', message: 'Error message' }]
422423
return []
@@ -445,11 +446,10 @@ describe('Form', () => {
445446

446447
await setValue(input, validInputValue)
447448
// Waiting because of the debounced validation on input event.
448-
await new Promise((r) => setTimeout(r, 50))
449+
await new Promise(r => setTimeout(r, 50))
449450
expect(wrapper.text()).not.toContain('Error message')
450451
})
451452

452-
453453
describe('api', async () => {
454454
let wrapper: any
455455
let form: any
@@ -462,7 +462,7 @@ describe('Form', () => {
462462
UForm,
463463
UInput
464464
},
465-
setup () {
465+
setup() {
466466
const form = ref()
467467
const state = reactive({})
468468
const schema = z.object({
@@ -605,7 +605,7 @@ describe('Form', () => {
605605
UForm,
606606
UInput
607607
},
608-
setup () {
608+
setup() {
609609
const form = ref()
610610
const state = reactive({ nested: {} })
611611
const schema = z.object({
@@ -618,7 +618,6 @@ describe('Form', () => {
618618
field: z.string().min(1)
619619
})
620620

621-
622621
const onError = vi.fn()
623622
const onSubmit = vi.fn()
624623

@@ -651,7 +650,7 @@ describe('Form', () => {
651650
expect(wrapper.setupState.onSubmit).not.toHaveBeenCalled()
652651
expect(wrapper.setupState.onError).toHaveBeenCalledTimes(1)
653652
const onErrorCallArgs = wrapper.setupState.onError.mock.lastCall[0]
654-
expect(onErrorCallArgs.childrens[0].errors).toMatchObject([ { id: 'nestedInput', name: 'field', message: 'Required' } ])
653+
expect(onErrorCallArgs.childrens[0].errors).toMatchObject([{ id: 'nestedInput', name: 'field', message: 'Required' }])
655654
expect(onErrorCallArgs.errors).toMatchObject([
656655
{ id: 'emailInput', name: 'email', message: 'Required' },
657656
{ id: 'passwordInput', name: 'password', message: 'Required' }

test/components/Input.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect, test } from 'vitest'
2+
import { mount } from '@vue/test-utils'
23
import Input, { type InputProps } from '../../src/runtime/components/Input.vue'
34
import ComponentRender from '../component-render'
4-
import { mount } from '@vue/test-utils'
55

66
describe('Input', () => {
77
it.each([
@@ -35,9 +35,9 @@ describe('Input', () => {
3535
})
3636

3737
it.each([
38-
['with .trim modifier', { props: { modelModifiers: { trim: true } } }, { input: 'input ', expected: 'input' } ],
39-
['with .number modifier', { props: { modelModifiers: { number: true } } }, { input: '42', expected: 42 } ],
40-
['with .lazy modifier', { props: { modelModifiers: { lazy: true } } }, { input: 'input', expected: 'input' } ]
38+
['with .trim modifier', { props: { modelModifiers: { trim: true } } }, { input: 'input ', expected: 'input' }],
39+
['with .number modifier', { props: { modelModifiers: { number: true } } }, { input: '42', expected: 42 }],
40+
['with .lazy modifier', { props: { modelModifiers: { lazy: true } } }, { input: 'input', expected: 'input' }]
4141
])('%s works', async (_nameOrHtml: string, options: { props?: any, slots?: any }, spec: { input: any, expected: any }) => {
4242
const wrapper = mount(Input, {
4343
...options

test/components/RadioGroup.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from 'vitest'
2+
import { defu } from 'defu'
23
import RadioGroup, { type RadioGroupProps } from '../../src/runtime/components/RadioGroup.vue'
34
import ComponentRender from '../component-render'
4-
import { defu } from 'defu'
55

66
const defaultOptions = [
77
{ value: '1', label: 'Option 1' },

test/components/Textarea.spec.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect, test } from 'vitest'
2+
import { mount } from '@vue/test-utils'
23
import Textarea, { type TextareaProps } from '../../src/runtime/components/Textarea.vue'
34
import ComponentRender from '../component-render'
4-
import { mount } from '@vue/test-utils'
55

66
describe('Textarea', () => {
77
it.each([
@@ -12,26 +12,25 @@ describe('Textarea', () => {
1212
['with required', { props: { required: true } }],
1313
['with disabled', { props: { disabled: true } }],
1414
['with rows', { props: { rows: 5 } }],
15-
['with size', { props: { size: 'sm' } }],
16-
['with color', { props: { color: 'blue' } }],
15+
['with size', { props: { size: 'sm' as const } }],
16+
['with color', { props: { color: 'blue' as const } }],
1717
['with size 2xs', { props: { size: '2xs' as const } }],
1818
['with size xs', { props: { size: 'xs' as const } }],
1919
['with size sm', { props: { size: 'sm' as const } }],
2020
['with size md', { props: { size: 'md' as const } }],
2121
['with size lg', { props: { size: 'lg' as const } }],
2222
['with size xl', { props: { size: 'xl' as const } }],
23-
['with variant', { variant: 'outline' }],
23+
['with variant', { props: { variant: 'outline' as const } }],
2424
['with default slot', { slots: { default: () => 'Default slot' } }]
25-
// @ts-ignore
26-
])('renders %s correctly', async (nameOrHtml: string, options: { props: TextareaProps, slots?: any }) => {
25+
])('renders %s correctly', async (nameOrHtml: string, options: { props?: TextareaProps, slots?: any }) => {
2726
const html = await ComponentRender(nameOrHtml, options, Textarea)
2827
expect(html).toMatchSnapshot()
2928
})
3029

3130
it.each([
32-
['with .trim modifier', { props: { modelModifiers: { trim: true } } }, { input: 'input ', expected: 'input' } ],
33-
['with .number modifier', { props: { modelModifiers: { number: true } } }, { input: '42', expected: 42 } ],
34-
['with .lazy modifier', { props: { modelModifiers: { lazy: true } } }, { input: 'input', expected: 'input' } ]
31+
['with .trim modifier', { props: { modelModifiers: { trim: true } } }, { input: 'input ', expected: 'input' }],
32+
['with .number modifier', { props: { modelModifiers: { number: true } } }, { input: '42', expected: 42 }],
33+
['with .lazy modifier', { props: { modelModifiers: { lazy: true } } }, { input: 'input', expected: 'input' }]
3534
])('%s works', async (_nameOrHtml: string, options: { props?: any, slots?: any }, spec: { input: any, expected: any }) => {
3635
const wrapper = await mount(Textarea, {
3736
...options

0 commit comments

Comments
 (0)