Skip to content

Commit 88c8ea4

Browse files
committed
update test
1 parent 0796c80 commit 88c8ea4

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

test/specs/vue-numeric.spec.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ import { mount } from 'avoriaz'
55
import VueNumeric from '@/vue-numeric'
66

77
describe('vue-numeric.vue', () => {
8-
let el
9-
10-
beforeEach(() => {
11-
el = document.createElement('div')
12-
document.body.appendChild(el)
13-
})
14-
158
it('has name', () => {
169
const wrapper = mount(VueNumeric, { propsData: { value: 0 } })
1710
expect(wrapper.name()).to.equal('vue-numeric')
@@ -100,47 +93,56 @@ describe('vue-numeric.vue', () => {
10093
expect(wrapper.vm.maxValue).to.equal(undefined)
10194
})
10295

103-
it('cannot exceed max props', done => {
104-
const vm = new Vue({
105-
el,
96+
it('apply class when toggle read-only mode on', done => {
97+
const propsData = { value: 3000, readOnly: false, readOnlyClass: 'testclass' }
98+
const wrapper = mount(VueNumeric, { propsData })
99+
100+
wrapper.setProps({ readOnly: true })
101+
102+
wrapper.instance().$nextTick(() => {
103+
expect(wrapper.instance().$el.className).to.equal('testclass')
104+
done()
105+
})
106+
})
107+
108+
it('cannot exceed max props', () => {
109+
const component = Vue.extend({
106110
data: () => ({ total: 150 }),
107111
template: '<div><vue-numeric v-model="total" :max="100"></vue-numeric></div>',
108112
components: { VueNumeric }
109-
}).$mount()
110-
111-
Vue.nextTick(() => {
112-
expect(vm.$el.firstChild.value.trim()).to.equal('100')
113-
done()
114113
})
114+
115+
const wrapper = mount(component)
116+
expect(wrapper.data().total).to.equal(100)
115117
})
116118

117-
it('cannot below min props', done => {
118-
const vm = new Vue({
119-
el,
119+
it('cannot below min props', () => {
120+
const component = Vue.extend({
120121
data: () => ({ total: 150 }),
121122
template: '<div><vue-numeric v-model="total" :min="200"></vue-numeric></div>',
122123
components: { VueNumeric }
123-
}).$mount()
124-
125-
Vue.nextTick(() => {
126-
expect(vm.$el.firstChild.value.trim()).to.equal('200')
127-
done()
128124
})
125+
126+
const wrapper = mount(component)
127+
expect(wrapper.data().total).to.equal(200)
129128
})
130129

131-
it('updates value with format if without focus', done => {
130+
it('updates delayed value with format if without focus', done => {
131+
const el = document.createElement('div')
132132
const vm = new Vue({
133133
el,
134134
data: () => ({ total: 0 }),
135135
template: '<div><vue-numeric v-model="total"></vue-numeric></div>',
136136
components: { VueNumeric }
137137
}).$mount()
138138

139-
vm.total = 3000
139+
setTimeout(() => {
140+
vm.total = 3000
141+
}, 100);
140142

141-
Vue.nextTick(() => {
143+
setTimeout(() => {
142144
expect(vm.$el.firstChild.value.trim()).to.equal('3,000')
143145
done()
144-
})
146+
}, 500);
145147
})
146148
})

0 commit comments

Comments
 (0)