forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetValue.spec.js
65 lines (53 loc) · 2.27 KB
/
setValue.spec.js
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
import ComponentWithInput from '~resources/components/component-with-input.vue'
import { describeWithShallowAndMount } from '~resources/utils'
describeWithShallowAndMount('setValue', mountingMethod => {
it('sets element value', () => {
const wrapper = mountingMethod(ComponentWithInput)
const input = wrapper.find('input[type="text"]')
input.setValue('foo')
expect(input.element.value).to.equal('foo')
})
it('updates dom with v-model', () => {
const wrapper = mountingMethod(ComponentWithInput)
const input = wrapper.find('input[type="text"]')
input.setValue('input text awesome binding')
expect(wrapper.text()).to.contain('input text awesome binding')
})
it('throws error if wrapper does not contain element', () => {
const wrapper = mountingMethod({ template: '<div><p/></div>' })
const p = wrapper.find('p')
p.element = null
const fn = () => p.setValue('')
const message = '[vue-test-utils]: cannot call wrapper.setValue() on a wrapper without an element'
expect(fn)
.to.throw()
.with.property('message', message)
})
it('throws error if element is select', () => {
const message =
'wrapper.setValue() cannot be called on a <select> element. Use wrapper.setSelected() instead'
shouldThrowErrorOnElement('select', message)
})
it('throws error if element is radio', () => {
const message =
'wrapper.setValue() cannot be called on a <input type="radio" /> element. Use wrapper.setChecked() instead'
shouldThrowErrorOnElement('input[type="radio"]', message)
})
it('throws error if element is checkbox', () => {
const message =
'wrapper.setValue() cannot be called on a <input type="checkbox" /> element. Use wrapper.setChecked() instead'
shouldThrowErrorOnElement('input[type="checkbox"]', message)
})
it('throws error if element is not valid', () => {
const message = 'wrapper.setValue() cannot be called on this element'
shouldThrowErrorOnElement('#label-el', message)
})
function shouldThrowErrorOnElement (selector, message) {
const wrapper = mountingMethod(ComponentWithInput)
const input = wrapper.find(selector)
const fn = () => input.setValue('')
expect(fn)
.to.throw()
.with.property('message', '[vue-test-utils]: ' + message)
}
})