Skip to content

Commit

Permalink
test: 优化单元测试 🌦️🌦️🌦️
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Feb 17, 2023
1 parent e899238 commit ceece1d
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 64 deletions.
3 changes: 2 additions & 1 deletion packages/fighting-design/alert/__test__/alert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FAlert } from '../index'
import { FIGHTING_TYPE } from '../../_tokens'
import type { FightingType } from '../../_interface'

describe('FAlert', () => {
test('class', () => {
Expand All @@ -10,7 +11,7 @@ describe('FAlert', () => {
})

test('type', () => {
FIGHTING_TYPE.forEach(item => {
FIGHTING_TYPE.forEach((item: FightingType): void => {
const wrapper = mount(FAlert, {
props: { type: item }
})
Expand Down
5 changes: 3 additions & 2 deletions packages/fighting-design/avatar/__test__/avatar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FAvatar } from '../index'
import { FIGHTING_SIZE, FIGHTING_FIT } from '../../_tokens'
import type { FightingFit, FightingSize } from '../../_interface'

describe('FAvatar', () => {
test('class', () => {
Expand All @@ -25,7 +26,7 @@ describe('FAvatar', () => {
})

test('fit', () => {
FIGHTING_FIT.forEach(item => {
FIGHTING_FIT.forEach((item: FightingFit): void => {
const wrapper = mount(FAvatar, {
props: { fit: item }
})
Expand All @@ -34,7 +35,7 @@ describe('FAvatar', () => {
})

test('size', () => {
FIGHTING_SIZE.forEach(item => {
FIGHTING_SIZE.forEach((item: FightingSize): void => {
const wrapper = mount(FAvatar, {
props: { size: item }
})
Expand Down
3 changes: 2 additions & 1 deletion packages/fighting-design/badge/__test__/badge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FBadge } from '../index'
import { FIGHTING_TYPE } from '../../_tokens'
import type { FightingType } from '../../_interface'

describe('FBadge', () => {
test('class', () => {
Expand All @@ -12,7 +13,7 @@ describe('FBadge', () => {
})

test('type', () => {
FIGHTING_TYPE.forEach(item => {
FIGHTING_TYPE.forEach((item: FightingType): void => {
const wrapper = mount(FBadge, {
props: { type: item }
})
Expand Down
12 changes: 7 additions & 5 deletions packages/fighting-design/button/__test__/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { describe, expect, test } from 'vitest'
import { FButton } from '../index'
import { useColor } from '../../_hooks'
import { FIGHTING_SIZE, FIGHTING_TYPE, FIGHTING_TARGET } from '../../_tokens'
import type { ButtonNative, ButtonTarget } from '../index'
import type { FightingType, FightingSize } from '../../_interface'

describe('FButton', () => {
test('class', () => {
Expand Down Expand Up @@ -55,7 +57,7 @@ describe('FButton', () => {
})

test('size', () => {
FIGHTING_SIZE.forEach(item => {
FIGHTING_SIZE.forEach((item: FightingSize): void => {
const wrapper = mount(FButton, {
props: { size: item }
})
Expand All @@ -78,7 +80,7 @@ describe('FButton', () => {
})

test('target', () => {
FIGHTING_TARGET.forEach(item => {
FIGHTING_TARGET.forEach((item: ButtonTarget): void => {
const wrapper = mount(FButton, {
props: { href: 'https://tianyuhao.cn', target: item }
})
Expand All @@ -101,7 +103,7 @@ describe('FButton', () => {
})

test('type', () => {
FIGHTING_TYPE.forEach(item => {
FIGHTING_TYPE.forEach((item: FightingType): void => {
const wrapper = mount(FButton, {
props: { type: item }
})
Expand Down Expand Up @@ -145,8 +147,8 @@ describe('FButton', () => {
})

test('native-type', () => {
const nativeType = ['button', 'submit', 'reset'] as const
nativeType.forEach(item => {
const nativeTypes: ButtonNative[] = ['button', 'submit', 'reset']
nativeTypes.forEach((item: ButtonNative): void => {
const wrapper = mount(FButton, {
props: { nativeType: item }
})
Expand Down
5 changes: 3 additions & 2 deletions packages/fighting-design/card/__test__/card.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FCard } from '../index'
import type { CardShadow } from '../index'

describe('FCard', () => {
test('class', () => {
Expand Down Expand Up @@ -32,8 +33,8 @@ describe('FCard', () => {
})

test('shadow', () => {
const shadow = ['hover', 'always'] as const
shadow.forEach(item => {
const shadows: CardShadow[] = ['hover', 'always']
shadows.forEach((item: CardShadow): void => {
const wrapper = mount(FCard, {
props: { shadow: item }
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,17 @@ describe('CollapseAnimation', () => {

test('opened', () => {
const wrapper = mount(FCollapseAnimation, {
props: {
opened: false
},
slots: {
default: 'collapse-animation'
}
props: { opened: false },
slots: { default: 'collapse-animation' }
})
wrapper.get('.f-collapse-animation')
expect(wrapper.attributes().style).toContain('height: 0px;')
})

test('disabled', async () => {
const wrapper = mount(FCollapseAnimation, {
props: {
opened: false,
disabled: true
},
slots: {
default: 'collapse-animation'
}
props: { opened: false, disabled: true },
slots: { default: 'collapse-animation' }
})
await wrapper.setProps({ opened: true })
expect(wrapper.attributes().style).toContain('height: 0px;')
Expand Down
16 changes: 3 additions & 13 deletions packages/fighting-design/dialog/__test__/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ import { EMIT_VISIBLE } from '../../_tokens'
describe('FDialog', () => {
test('class', () => {
const wrapper = mount(FDialog, {
props: {
visible: true
}
props: { visible: true }
})
expect(wrapper.find('div').classes()).toContain('f-popup')
})

test('title', () => {
const wrapper = mount(FDialog, {
props: {
visible: true,
title: '标题'
}
props: { visible: true, title: '标题' }
})
expect(wrapper.find('.f-dialog__header-title').text()).toContain('标题')
})
Expand All @@ -37,10 +32,7 @@ describe('FDialog', () => {

test('width', () => {
const wrapper = mount(FDialog, {
props: {
visible: true,
width: '200px'
}
props: { visible: true, width: '200px' }
})
expect(wrapper.find('.f-dialog').attributes('style')).toContain('width: 200px')
})
Expand Down Expand Up @@ -85,8 +77,6 @@ describe('FDialog', () => {
await wrapper.get('.f-popup__container').trigger('click.self')
expect(wrapper.emitted(EMIT_VISIBLE)?.[0][0]).toBe(false)
await wrapper.setProps({ visible: false })
// 应该使用 js-dom。如果使用 happy-dom,下面的测试就会失败。
// 查看这个 issue https://github.com/vuejs/test-utils/issues/1704
expect(wrapper.find('.f-dialog').isVisible()).toBe(false)
})

Expand Down
5 changes: 1 addition & 4 deletions packages/fighting-design/divider/__test__/divider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { describe, expect, test } from 'vitest'
import { FDivider } from '../index'
import type { DividerType, DividerPosition } from '../index'

const text = '分割线'

describe('FDivider', () => {

test('class', () => {
Expand All @@ -26,7 +24,6 @@ describe('FDivider', () => {
props: { vertical: true }
})
expect(wrapper.classes()).toContain('f-divider__vertical')
// expect(wrapper.find('span').exists()).toBe(false)
})

test('position', () => {
Expand All @@ -41,7 +38,7 @@ describe('FDivider', () => {

test('fontColor', () => {
const wrapper = mount(FDivider, {
slots: { default: text },
slots: { default: '分割线' },
props: { fontColor: 'green' }
})
expect(wrapper.attributes('style')).toContain('--divider-font-color: green')
Expand Down
4 changes: 1 addition & 3 deletions packages/fighting-design/drawer/__test__/drawer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ describe('FDrawer', () => {

test('title', () => {
const wrapper = mount(FDrawer, {
props: {
title: '标题'
}
props: { title: '标题' }
})
expect(wrapper.find('.f-drawer__header-title').text()).toContain('标题')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ describe('DropdownItem', () => {

test('disabled', () => {
const wrapper = mount(FDropdownItem, {
props: {
disabled: true
}
props: { disabled: true }
})
expect(wrapper.classes()).toContain('f-dropdown-item__disabled')
})
Expand Down
4 changes: 1 addition & 3 deletions packages/fighting-design/empty/__test__/empty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ describe('FEmpty', () => {

test('content', () => {
const wrapper = mount(FEmpty, {
props: {
content: '内容啊'
}
props: { content: '内容啊' }
})
expect(wrapper.find('.f-empty__content').text()).toContain('内容啊')
})
Expand Down
3 changes: 2 additions & 1 deletion packages/fighting-design/image/__test__/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FImage } from '../index'
import { FIGHTING_FIT } from '../../_tokens'
import type { ImageFit } from '../index'

describe('FImage', () => {
test('class', () => {
Expand Down Expand Up @@ -32,7 +33,7 @@ describe('FImage', () => {
})

test('fit', () => {
FIGHTING_FIT.forEach(item => {
FIGHTING_FIT.forEach((item: ImageFit): void => {
const wrapper = mount(FImage, {
props: { fit: item }
})
Expand Down
8 changes: 5 additions & 3 deletions packages/fighting-design/input/__test__/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FInput } from '../index'
import { FIGHTING_SIZE } from '../../_tokens'
import type { InputType } from '../index'
import type { FightingSize } from '../../_interface'

describe('Input', () => {
test('class', () => {
Expand All @@ -11,8 +13,8 @@ describe('Input', () => {
})

test('type', () => {
const size = ['text', 'password', 'number'] as const
size.forEach(item => {
const types: InputType[] = ['text', 'password', 'number']
types.forEach((item: InputType): void => {
const wrapper = mount(FInput, {
props: { type: item }
})
Expand All @@ -21,7 +23,7 @@ describe('Input', () => {
})

test('size', () => {
FIGHTING_SIZE.forEach(item => {
FIGHTING_SIZE.forEach((item: FightingSize): void => {
const wrapper = mount(FInput, {
props: { size: item }
})
Expand Down
3 changes: 2 additions & 1 deletion packages/fighting-design/list/__test__/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FList } from '../index'
import { FIGHTING_SIZE } from '../../_tokens'
import type { FightingSize } from '../../_interface'

describe('FList', () => {
test('class', () => {
Expand Down Expand Up @@ -32,7 +33,7 @@ describe('FList', () => {
})

test('size', () => {
FIGHTING_SIZE.forEach(item => {
FIGHTING_SIZE.forEach((item: FightingSize): void => {
const wrapper = mount(FList, {
props: { size: item }
})
Expand Down
4 changes: 1 addition & 3 deletions packages/fighting-design/loading/__test__/loading.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import FLoadingVue from '../src/loading.vue'
describe('FLoading', () => {
test('class', () => {
const wrapper = mount(FLoadingVue, {
props: {
visible: true
}
props: { visible: true }
})
expect(wrapper.classes()).toContain('f-loading')
})
Expand Down
3 changes: 2 additions & 1 deletion packages/fighting-design/switch/__test__/switch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FSwitch } from '../index'
import { FIGHTING_SIZE } from '../../_tokens'
import type { FightingSize } from '../../_interface'

describe('FSwitch', () => {
test('class', () => {
Expand All @@ -10,7 +11,7 @@ describe('FSwitch', () => {
})

test('size', () => {
FIGHTING_SIZE.forEach(item => {
FIGHTING_SIZE.forEach((item: FightingSize): void => {
const wrapper = mount(FSwitch, {
props: { size: item }
})
Expand Down
3 changes: 2 additions & 1 deletion packages/fighting-design/tag/__test__/tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FTag } from '../index'
import { FIGHTING_SIZE, FIGHTING_TYPE } from '../../_tokens'
import type { FightingType } from '../../_interface'

describe('FTag', () => {
test('class', () => {
Expand All @@ -10,7 +11,7 @@ describe('FTag', () => {
})

test('type', () => {
FIGHTING_TYPE.forEach(item => {
FIGHTING_TYPE.forEach((item: FightingType): void => {
const wrapper = mount(FTag, {
props: { type: item }
})
Expand Down
9 changes: 5 additions & 4 deletions packages/fighting-design/watermark/__test__/watermark.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// import { mount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
// import { FWatermark } from '../index'
import { FWatermark } from '../index'

describe('FWatermark', () => {
test('test', () => {
expect(1 + 1).toBe(2)
test('class', () => {
const wrapper = mount(FWatermark)
expect(wrapper.classes()).toContain('f-watermark')
})
})

0 comments on commit ceece1d

Please sign in to comment.