From 55c2fc3dc20ad25f88601d10a7249f312ad3458c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=98=8A=E7=BF=94?= <673686754@qq.com> Date: Fri, 4 Jan 2019 10:05:07 +0800 Subject: [PATCH] unit test: d2-container-card Former-commit-id: ec0d88699b516228939350bc91d2a19660e2daa1 [formerly ec0d88699b516228939350bc91d2a19660e2daa1 [formerly ec0d88699b516228939350bc91d2a19660e2daa1 [formerly ec0d88699b516228939350bc91d2a19660e2daa1 [formerly ed5f0a35cfeee08b444029b74ad8755cf2a8e35e [formerly 5235553320b656a9c12222faa18225b2b1ed54d8]]]]] Former-commit-id: 634539e313a27a71aab2d2e18982ec4e735dc93b Former-commit-id: f1537450ffea60639b8f11cbbe40058c5aece33a Former-commit-id: 58b5ae217a39f20c038b2d999f178359e49828d5 [formerly 105e09af8933da9f89591fae6acb2468ba706c96] Former-commit-id: 96c2b40a5b857599958ce75a75073983788b3fbe Former-commit-id: cecafe15a08e8f279767a45933c814bf948240cc Former-commit-id: ed8e45510ec0f518185555c9ebdc9e460d995614 Former-commit-id: 574e00143fbaabfbb4f462ff883b65c5d427c649 Former-commit-id: 5e667452de548c6482700f6c0ad1956af21bb1ed --- tests/unit/d2-container-card.spec.js | 34 ++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) 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') }) })