test: lint

This commit is contained in:
Benjamin Canac
2024-04-12 14:00:58 +02:00
parent 9993b6727a
commit 290e4ce150
6 changed files with 40 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
import path from 'node:path'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import path from 'path'
export default async function (nameOrHtml: string, options: any, component: any) {
let html: string

View File

@@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest'
import { defu } from 'defu'
import Checkbox, { type CheckboxProps } from '../../src/runtime/components/Checkbox.vue'
import ComponentRender from '../component-render'
import { defu } from 'defu'
describe('Checkbox', () => {
it.each([
@@ -16,15 +16,14 @@ describe('Checkbox', () => {
['with indeterminate', { props: { indeterminate: true } }],
['with help', { props: { label: 'Label', help: 'Help' } }],
['with required', { props: { label: 'Label', required: true } }],
['with custom color', { props: { label: 'Label', color: 'red' } }],
['with custom color', { props: { label: 'Label', color: 'red' as const } }],
['with size 2xs', { props: { size: '2xs' as const } }],
['with size xs', { props: { size: 'xs' as const } }],
['with size sm', { props: { size: 'sm' as const } }],
['with size md', { props: { size: 'md' as const } }],
['with size lg', { props: { size: 'lg' as const } }],
['with size xl', { props: { size: 'xl' as const } }]
// @ts-ignore
])('renders %s correctly', async (nameOrHtml: string, options: { props?: CheckboxProps }) => {
])('renders %s correctly', async (nameOrHtml: string, options: { props?: CheckboxProps, slots?: any }) => {
const html = await ComponentRender(nameOrHtml, defu(options, { props: { id: 42 } }), Checkbox)
expect(html).toMatchSnapshot()
})

View File

@@ -1,5 +1,13 @@
import { reactive, ref, nextTick } from 'vue'
import { describe, it, expect, test, beforeEach, vi } from 'vitest'
import type { DOMWrapper, VueWrapper } from '@vue/test-utils'
import { flushPromises } from '@vue/test-utils'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { z } from 'zod'
import * as yup from 'yup'
import Joi from 'joi'
import * as valibot from 'valibot'
import ComponentRender from '../component-render'
import type { FormProps } from '../../src/runtime/components/Form.vue'
import {
UForm,
@@ -15,14 +23,6 @@ import {
// UToggle,
// URange
} from '#components'
import { DOMWrapper, flushPromises, VueWrapper } from '@vue/test-utils'
import ComponentRender from '../component-render'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { z } from 'zod'
import * as yup from 'yup'
import Joi from 'joi'
import * as valibot from 'valibot'
async function triggerEvent(
el: DOMWrapper<Element> | VueWrapper<any, any>,
@@ -47,6 +47,7 @@ async function renderForm (options: {
slotTemplate: string
}) {
const state = reactive({})
return await mountSuspended(UForm, {
props: {
id: 42,
@@ -55,7 +56,7 @@ async function renderForm (options: {
},
slots: {
default: {
// @ts-ignore
// @ts-expect-error setup does not exist on type
setup() {
return { state, ...options.slotVars }
},
@@ -152,7 +153,7 @@ describe('Form', () => {
await triggerEvent(form, 'submit.prevent')
// @ts-ignore
// @ts-expect-error object is possibly undefined
expect(wrapper.emitted('error')[0][0].errors).toMatchObject([
{
id: 'password',
@@ -445,11 +446,10 @@ describe('Form', () => {
await setValue(input, validInputValue)
// Waiting because of the debounced validation on input event.
await new Promise((r) => setTimeout(r, 50))
await new Promise(r => setTimeout(r, 50))
expect(wrapper.text()).not.toContain('Error message')
})
describe('api', async () => {
let wrapper: any
let form: any
@@ -618,7 +618,6 @@ describe('Form', () => {
field: z.string().min(1)
})
const onError = vi.fn()
const onSubmit = vi.fn()

View File

@@ -1,7 +1,7 @@
import { describe, it, expect, test } from 'vitest'
import { mount } from '@vue/test-utils'
import Input, { type InputProps } from '../../src/runtime/components/Input.vue'
import ComponentRender from '../component-render'
import { mount } from '@vue/test-utils'
describe('Input', () => {
it.each([

View File

@@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest'
import { defu } from 'defu'
import RadioGroup, { type RadioGroupProps } from '../../src/runtime/components/RadioGroup.vue'
import ComponentRender from '../component-render'
import { defu } from 'defu'
const defaultOptions = [
{ value: '1', label: 'Option 1' },

View File

@@ -1,7 +1,7 @@
import { describe, it, expect, test } from 'vitest'
import { mount } from '@vue/test-utils'
import Textarea, { type TextareaProps } from '../../src/runtime/components/Textarea.vue'
import ComponentRender from '../component-render'
import { mount } from '@vue/test-utils'
describe('Textarea', () => {
it.each([
@@ -12,18 +12,17 @@ describe('Textarea', () => {
['with required', { props: { required: true } }],
['with disabled', { props: { disabled: true } }],
['with rows', { props: { rows: 5 } }],
['with size', { props: { size: 'sm' } }],
['with color', { props: { color: 'blue' } }],
['with size', { props: { size: 'sm' as const } }],
['with color', { props: { color: 'blue' as const } }],
['with size 2xs', { props: { size: '2xs' as const } }],
['with size xs', { props: { size: 'xs' as const } }],
['with size sm', { props: { size: 'sm' as const } }],
['with size md', { props: { size: 'md' as const } }],
['with size lg', { props: { size: 'lg' as const } }],
['with size xl', { props: { size: 'xl' as const } }],
['with variant', { variant: 'outline' }],
['with variant', { props: { variant: 'outline' as const } }],
['with default slot', { slots: { default: () => 'Default slot' } }]
// @ts-ignore
])('renders %s correctly', async (nameOrHtml: string, options: { props: TextareaProps, slots?: any }) => {
])('renders %s correctly', async (nameOrHtml: string, options: { props?: TextareaProps, slots?: any }) => {
const html = await ComponentRender(nameOrHtml, options, Textarea)
expect(html).toMatchSnapshot()
})