Blame view

node_modules/bootstrap-vue/src/components/skeleton/skeleton-icon.spec.js 2.09 KB
4cd4fd28   郭伟龙   feat: 初始化项目
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { mount } from '@vue/test-utils'
import { IconsPlugin } from '../../icons'
import { Vue } from '../../vue'
import { BSkeletonIcon } from './skeleton-icon'

Vue.use(IconsPlugin)

describe('skeleton-icon', () => {
  it('root element is DIV and contains SVG', async () => {
    const wrapper = mount(BSkeletonIcon)

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.find('svg').exists()).toBe(true)

    wrapper.destroy()
  })

  it('default animation is `wave`', async () => {
    const wrapper = mount(BSkeletonIcon)

    expect(wrapper).toBeDefined()
    expect(wrapper.classes()).toContain('b-skeleton-animate-wave')

    wrapper.destroy()
  })

  it('has class `b-skeleton-animate-fade` when `animation="fade"` is set', async () => {
    const wrapper = mount(BSkeletonIcon, {
      propsData: {
        animation: 'fade'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.classes()).toContain('b-skeleton-animate-fade')

    wrapper.destroy()
  })

  it('`icon` prop works', async () => {
    const wrapper = mount(BSkeletonIcon, {
      propsData: {
        icon: 'heart'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.find('svg').exists()).toBe(true)
    expect(wrapper.find('svg').classes()).toContain('bi-heart')

    wrapper.destroy()
  })

  it('`icon-props` is passed correctly to icon', async () => {
    const wrapper = mount(BSkeletonIcon, {
      propsData: {
        icon: 'heart',
        iconProps: {
          fontScale: 2,
          variant: 'primary'
        }
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.find('svg').exists()).toBe(true)
    expect(wrapper.find('svg').classes()).toContain('text-primary')
    expect(wrapper.find('svg').element.style.fontSize).toBe('200%')

    wrapper.destroy()
  })

  it('accepts custom classes', async () => {
    const wrapper = mount(BSkeletonIcon, {
      context: {
        class: ['foobar']
      }
    })

    expect(wrapper.classes()).toContain('b-skeleton-icon-wrapper')
    expect(wrapper.classes()).toContain('foobar')

    wrapper.destroy()
  })
})