test(badge): add unit test (#388)

This commit is contained in:
Lyx 2023-08-16 09:28:37 +08:00 committed by GitHub
parent 75032bde35
commit 159fd4fc47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import { mountPcMode } from '@opentiny-internal/vue-test-utils'
import { describe, expect, test } from 'vitest'
import Badge from '@opentiny/vue-badge'
import { describe, expect, test } from 'vitest'
describe('PC Mode', () => {
const mount = mountPcMode
@ -53,7 +53,51 @@ describe('PC Mode', () => {
expect(wrapper.find('.badge__content').text()).toEqual('自定义')
})
test.todo('href 跳转链接')
test.todo('default slot 默认插槽自定义标记内容')
test.todo('hidden 消息已读动态隐藏标记')
test('href', () => {
const num = 1
const text = '跳转链接'
const wrapper = mount(() => <Badge value={num} href={"/"}>{text}</Badge>)
expect(wrapper.find('.tiny-badge a').exists()).toBe(true)
})
test('default slot', () => {
const wrapper = mount(() => {
return (
<Badge
value={1}
v-slots={{
default: () => <div class="badge__default__slot"></div>
}}
></Badge>
)
})
expect(wrapper.find('.badge__default__slot').exists()).toBe(true)
expect(wrapper.find('.badge__default__slot').text()).toEqual('插槽内容')
})
test('dynamic hidden', async () => {
const wrapper = mount(Badge, {
props: {
value: 2,
hidden: false
},
slots: {
default: () => <div class="badge__default__slot"></div>
},
})
expect(wrapper.find('.tiny-badge').exists()).toBe(true)
expect(wrapper.find('.tiny-badge__content-text').text()).toEqual('2')
expect(wrapper.find('.badge__default__slot').text()).toEqual('我的待办')
await wrapper.setProps({ value: 1 })
await wrapper.setProps({ hidden: 1 === 0 })
expect(wrapper.find('.tiny-badge').exists()).toBe(true)
expect(wrapper.find('.tiny-badge__content-text').text()).toEqual('1')
await wrapper.setProps({ value: 0 })
await wrapper.setProps({ hidden: 0 === 0 })
expect(wrapper.find('.tiny-badge').exists()).toBe(false)
})
})