d2-container-card.spec.js
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { mount } from '@vue/test-utils'
import D2ContainerCard from '@/components/d2-container/components/d2-container-card.vue'
describe('d2-container-card', () => {
// 存在且是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: '<div>body</div>',
header: '<div>header</div>',
footer: '<div>footer</div>'
}
})
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()
})
// props
it('has props', () => {
const wrapper = mount(D2ContainerCard, {
propsData: {
scrollDelay: 30
}
})
expect(wrapper.props().scrollDelay).toEqual(30)
})
// 渲染slot
it('has one or more slots', () => {
const wrapper = mount(D2ContainerCard, {
slots: {
default: '<div>body</div>',
header: '<div>header</div>',
footer: '<div>footer</div>'
}
})
expect(wrapper.text()).toMatch('header')
expect(wrapper.text()).toMatch('body')
expect(wrapper.text()).toMatch('footer')
})
})