From 0caf2fde7971478158fcd44e84d37ade9b2fcfe6 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 13:41:56 +0800 Subject: [PATCH] unit test: d2-container-ghost d2-container-ghost-bs Former-commit-id: a3bd22f5d907c9b001c21d8e0e5e1a448e4a479d [formerly a3bd22f5d907c9b001c21d8e0e5e1a448e4a479d [formerly a3bd22f5d907c9b001c21d8e0e5e1a448e4a479d [formerly a3bd22f5d907c9b001c21d8e0e5e1a448e4a479d [formerly 93ea6d53bd1ba2ba7670725357950bb0cb8f252f [formerly d753e72f3acc433edf54816392664e4879def36e]]]]] Former-commit-id: 3b70ea51df338250db8381c176d72a1e5bf2f14d Former-commit-id: b5963a8de1dbb6a72a96d9e742ce252f096095be Former-commit-id: e9e410815bd4ed055a2902a584ec85ef6135871c [formerly 0a0fe15a5cc62fb43daf67ffb9cdc0bfbff768e4] Former-commit-id: 67fe141b4c8f69884d5e01e48ea92dad742fc7ab Former-commit-id: 0481b77c2ff5dfdb542414db7b228a0f5110f7e8 Former-commit-id: 816185b58edb34b955b176a97e7801f3e8e74b2f Former-commit-id: c28a3c03c9c48b9e5a2c40f87e101957ce745733 Former-commit-id: 502aaf18d8b17acb8b16421998ce47277bf56818 --- tests/unit/d2-container-ghost-bs.spec.js | 65 ++++++++++++++++++++++++ tests/unit/d2-container-ghost.spec.js | 54 ++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 tests/unit/d2-container-ghost-bs.spec.js create mode 100644 tests/unit/d2-container-ghost.spec.js diff --git a/tests/unit/d2-container-ghost-bs.spec.js b/tests/unit/d2-container-ghost-bs.spec.js new file mode 100644 index 00000000..e8af6dc0 --- /dev/null +++ b/tests/unit/d2-container-ghost-bs.spec.js @@ -0,0 +1,65 @@ +import { mount } from '@vue/test-utils' +import D2ContainerGhostBs from '@/components/d2-container/components/d2-container-ghost-bs.vue' + +describe('d2-container-ghost-bs.vue', () => { + // 存在且是Vue组件实例 + it('is a vue instance', () => { + const wrapper = mount(D2ContainerGhostBs, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.exists()).toBeTruthy() + expect(wrapper.isVueInstance()).toBeTruthy() + }) + + // 包含特定类名 + it('contains specific classnames', () => { + const wrapper = mount(D2ContainerGhostBs, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.is('.d2-container-ghost-bs')).toBeTruthy() + expect(wrapper.contains('.d2-container-ghost-bs__header')).toBeTruthy() + expect(wrapper.contains('.d2-container-ghost-bs__body')).toBeTruthy() + expect(wrapper.contains('.d2-container-ghost-bs__footer')).toBeTruthy() + }) + + // betterScrollOptions prop + it('has a property named \'betterScrollOptions\'', () => { + const wrapper = mount(D2ContainerGhostBs, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + }, + propsData: { + betterScrollOptions: {} + } + }) + + expect(wrapper.props().betterScrollOptions).toEqual({}) + }) + + // 渲染slot + it('has one or more slots', () => { + const wrapper = mount(D2ContainerGhostBs, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.text()).toMatch('header') + expect(wrapper.text()).toMatch('body') + expect(wrapper.text()).toMatch('footer') + }) +}) \ No newline at end of file diff --git a/tests/unit/d2-container-ghost.spec.js b/tests/unit/d2-container-ghost.spec.js new file mode 100644 index 00000000..247e1e57 --- /dev/null +++ b/tests/unit/d2-container-ghost.spec.js @@ -0,0 +1,54 @@ +import { mount } from '@vue/test-utils' +import D2ContainerGhost from '@/components/d2-container/components/d2-container-ghost.vue' + +describe('d2-container-ghost.vue', () => { + // 存在且是Vue组件实例 + it('is a vue instance', () => { + const wrapper = mount(D2ContainerGhost) + + expect(wrapper.exists()).toBeTruthy() + expect(wrapper.isVueInstance()).toBeTruthy() + }) + + // 包含特定类名 + it('contains specific classnames', () => { + const wrapper = mount(D2ContainerGhost, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.is('.d2-container-ghost')).toBeTruthy() + expect(wrapper.contains('.d2-container-ghost__header')).toBeTruthy() + expect(wrapper.contains('.d2-container-ghost__body')).toBeTruthy() + expect(wrapper.contains('.d2-container-ghost__footer')).toBeTruthy() + }) + + // 节流间隔prop + it('has a property named \'scrollDelay\'', () => { + const wrapper = mount(D2ContainerGhost, { + propsData: { + scrollDelay: 30 + } + }) + + expect(wrapper.props().scrollDelay).toEqual(30) + }) + + // 渲染slot + it('has one or more slots', () => { + const wrapper = mount(D2ContainerGhost, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.text()).toMatch('header') + expect(wrapper.text()).toMatch('body') + expect(wrapper.text()).toMatch('footer') + }) +})