diff --git a/tests/unit/d2-container-card.spec.js b/tests/unit/d2-container-card.spec.js index 8b298425..b1eeed2e 100644 --- a/tests/unit/d2-container-card.spec.js +++ b/tests/unit/d2-container-card.spec.js @@ -2,7 +2,16 @@ import { mount } from '@vue/test-utils' import D2ContainerCard from '@/components/d2-container/components/d2-container-card.vue' describe('d2-container-card.vue', () => { - it('渲染slot', () => { + // 存在且是Vue组件实例 + it('is a vue instance', () => { + const wrapper = mount(D2ContainerCard) + + expect(wrapper.exists()).toBeTruthy() + expect(wrapper.isVueInstance()).toBeTruthy() + }) + + // 包含特定类名 + it('contains specific classnames', () => { const wrapper = mount(D2ContainerCard, { slots: { default: '
body
', @@ -11,8 +20,25 @@ describe('d2-container-card.vue', () => { } }) - expect(wrapper.html()).toContain('
body
') - expect(wrapper.html()).toContain('
header
') - expect(wrapper.html()).toContain('') + expect(wrapper.is('.d2-container-card')).toBeTruthy() + expect(wrapper.contains('.d2-container-card__header')).toBeTruthy() + expect(wrapper.contains('.d2-container-card__body')).toBeTruthy() + expect(wrapper.contains('.d2-container-card__body-card')).toBeTruthy() + expect(wrapper.contains('.d2-container-card__footer')).toBeTruthy() + }); + + // 渲染slot + it('has one or more slots', () => { + const wrapper = mount(D2ContainerCard, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.text()).toMatch('header') + expect(wrapper.text()).toMatch('body') + expect(wrapper.text()).toMatch('footer') }) })