This repository has been archived by the owner on Jun 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathCheckbox.spec.js
69 lines (65 loc) · 1.9 KB
/
Checkbox.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
66
67
68
69
import MdcCheckbox from 'src/Checkbox.vue'
import { createVM } from '../helpers/utils.js'
import { nextTick } from '../helpers/wait-for-update.js'
describe('Checkbox.vue', function () {
it('renders checkbox', function () {
const vm = createVM(this, function (h) {
return (
<MdcCheckbox />
)
}, {
components: { MdcCheckbox },
})
vm.$('input').should.have.attr('type', 'checkbox')
})
it('works with v-model and bool', function (done) {
const vm = createVM(this, `<MdcCheckbox v-model="checked"/>`, {
data: {
checked: true,
},
components: { MdcCheckbox },
})
vm.checked.should.be.true
vm.$('input').should.be.checked
vm.checked = false
nextTick().then(() => {
vm.checked.should.be.false
vm.$('input').should.not.be.checked
}).then(done)
})
it('works with v-model and arrays', function (done) {
const vm = createVM(this, `
<MdcCheckbox class="one" v-model="opts" value="one"/>
<MdcCheckbox class="two" v-model="opts" value="two"/>
`, {
data: {
opts: ['one'],
},
components: { MdcCheckbox },
})
vm.opts.should.eql(['one'])
vm.$('.one').should.be.checked
vm.$('.two').should.not.be.checked
vm.$('.one input').should.have.value('one')
vm.opts = ['one', 'two']
nextTick().then(() => {
vm.opts.should.eql(['one', 'two'])
vm.$('.one').should.be.checked
vm.$('.two').should.be.checked
vm.$('.one input').click()
}).then(() => {
vm.opts.should.eql(['two'])
vm.$('.one').should.be.not.checked
vm.$('.two').should.be.checked
}).then(done)
})
it('can have classic attrs: id, disabled', function () {
const vm = createVM(this, `
<MdcCheckbox id="foo" disabled />
`, {
components: { MdcCheckbox },
})
vm.$('input').should.have.attr('disabled')
vm.$('input').should.have.id('foo')
})
})