Skip to content

Commit

Permalink
test: descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jun 14, 2024
1 parent bdaf976 commit 1a53143
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/packages/descriptions/__tests__/Descriptions.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import Descriptions from '../index'
import { Tooltip } from 'ant-design-vue'

describe('Descriptions', () => {
it('render', async () => {
const wrapper = mount(Descriptions)
expect(wrapper.exists()).toBeTruthy()
})

it('props', async () => {
const wrapper = mount(Descriptions, {
props: {
title: 'Test',
params: { test: '123' },
request: (params) => {
return Promise.resolve({ data: {} })
},
onLoad: (value) => {
console.log(value)
},
onRequestError: (error) => {
console.log(error)
}
},
slots: {
default: () => {
return [
<Descriptions.Item label={'label'}/>,
<Descriptions.Item label={'label'}>
123
</Descriptions.Item>,
<Descriptions.Item valueType={'text'} label={'label'}/>
]
},
extra: () => {
return (<Tooltip>123</Tooltip>)
}
}
})
expect(wrapper.exists()).toBeTruthy()
})

it('props columns', async () => {
const wrapper = mount(Descriptions, {
props: {
title: () => 'Test',
params: { test: '123' },
columns: [
{
title: () => 'label',
valueType: 'text',
dataIndex: 'text',
index: '1'
}
],
request: (params) => {
return Promise.reject('error')
},
onLoad: (value) => {
console.log(value)
},
onRequestError: (error) => {
console.log(error)
}
}
})
expect(wrapper.exists()).toBeTruthy()
})
})
22 changes: 22 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { config } from '@vue/test-utils'

config.global.stubs = {
transition: false,
'transition-group': false,
}

global.window.resizeTo = (width, height) => {
global.window.innerWidth = width || global.window.innerWidth
global.window.innerHeight = height || global.window.innerHeight
global.window.dispatchEvent(new Event('resize'))
}

global.window.scrollTo = () => {}

global.window.matchMedia = (query) => {
return {
matches: false,
addListener: () => {},
removeListener: () => {}
}
}
1 change: 1 addition & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineConfig((configEnv) => {
return mergeConfig(viteConfig(configEnv), defineConfig({
test: {
environment: 'jsdom',
setupFiles: ['./tests/setup.js'],
include: ['**/*.{test,spec,type-test}.{js,mjs,cjs,ts,tsx,jsx}'],
coverage: {
exclude: [
Expand Down

0 comments on commit 1a53143

Please sign in to comment.