Blame view

node_modules/bootstrap-vue/src/components/form/form.spec.js 2.59 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
87
88
89
90
91
92
93
94
95
96
97
import { mount } from '@vue/test-utils'
import { BForm } from './form'

describe('form', () => {
  it('has expected default structure', async () => {
    const wrapper = mount(BForm)

    expect(wrapper.element.tagName).toBe('FORM')
    expect(wrapper.classes().length).toBe(0)
    expect(wrapper.text()).toEqual('')

    wrapper.destroy()
  })

  it('renders default slot content', async () => {
    const wrapper = mount(BForm, {
      slots: {
        default: 'foobar'
      }
    })

    expect(wrapper.element.tagName).toBe('FORM')
    expect(wrapper.classes().length).toBe(0)
    expect(wrapper.attributes('id')).toBeUndefined()
    expect(wrapper.attributes('novalidate')).toBeUndefined()
    expect(wrapper.text()).toEqual('foobar')

    wrapper.destroy()
  })

  it('has class form-inline when prop inline set', async () => {
    const wrapper = mount(BForm, {
      propsData: {
        inline: true
      }
    })

    expect(wrapper.element.tagName).toBe('FORM')
    expect(wrapper.classes()).toContain('form-inline')
    expect(wrapper.classes().length).toBe(1)
    expect(wrapper.attributes('id')).toBeUndefined()
    expect(wrapper.attributes('novalidate')).toBeUndefined()
    expect(wrapper.text()).toEqual('')

    wrapper.destroy()
  })

  it('has class was-validation when prop validated set', async () => {
    const wrapper = mount(BForm, {
      propsData: {
        validated: true
      }
    })

    expect(wrapper.element.tagName).toBe('FORM')
    expect(wrapper.classes()).toContain('was-validated')
    expect(wrapper.classes().length).toBe(1)
    expect(wrapper.attributes('id')).toBeUndefined()
    expect(wrapper.attributes('novalidate')).toBeUndefined()
    expect(wrapper.text()).toEqual('')

    wrapper.destroy()
  })

  it('has user supplied id', async () => {
    const wrapper = mount(BForm, {
      propsData: {
        id: 'foo'
      }
    })

    expect(wrapper.element.tagName).toBe('FORM')
    expect(wrapper.classes().length).toBe(0)
    expect(wrapper.attributes('id')).toBeDefined()
    expect(wrapper.attributes('id')).toEqual('foo')
    expect(wrapper.attributes('novalidate')).toBeUndefined()
    expect(wrapper.text()).toEqual('')

    wrapper.destroy()
  })

  it('has attribute novalidate when prop novalidate set', async () => {
    const wrapper = mount(BForm, {
      propsData: {
        novalidate: true
      }
    })

    expect(wrapper.element.tagName).toBe('FORM')
    expect(wrapper.classes().length).toBe(0)
    expect(wrapper.attributes('id')).toBeUndefined()
    expect(wrapper.attributes('novalidate')).toBeDefined()
    expect(wrapper.text()).toEqual('')

    wrapper.destroy()
  })
})