diff --git a/tests/unit/d2-container-full.spec.js b/tests/unit/d2-container-full.spec.js new file mode 100644 index 00000000..39e8a744 --- /dev/null +++ b/tests/unit/d2-container-full.spec.js @@ -0,0 +1,54 @@ +import { mount } from '@vue/test-utils' +import D2ContainerFull from '@/components/d2-container/components/d2-container-full.vue' + +describe('d2-container-full.vue', () => { + // 存在且是Vue组件实例 + it('is a vue instance', () => { + const wrapper = mount(D2ContainerFull) + + expect(wrapper.exists()).toBeTruthy() + expect(wrapper.isVueInstance()).toBeTruthy() + }) + + // 包含特定类名 + it('contains specific classnames', () => { + const wrapper = mount(D2ContainerFull, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.is('.d2-container-full')).toBeTruthy() + expect(wrapper.contains('.d2-container-full__header')).toBeTruthy() + expect(wrapper.contains('.d2-container-full__body')).toBeTruthy() + expect(wrapper.contains('.d2-container-full__footer')).toBeTruthy() + }) + + // 节流间隔prop + it('has a property named \'scrollDelay\'', () => { + const wrapper = mount(D2ContainerFull, { + propsData: { + scrollDelay: 30 + } + }) + + expect(wrapper.props().scrollDelay).toEqual(30) + }) + + // 渲染slot + it('has one or more slots', () => { + const wrapper = mount(D2ContainerFull, { + slots: { + default: '
body
', + header: '
header
', + footer: '
footer
' + } + }) + + expect(wrapper.text()).toMatch('header') + expect(wrapper.text()).toMatch('body') + expect(wrapper.text()).toMatch('footer') + }) +})