@@ -58,9 +58,9 @@ describe('vue-numeric.vue', () => {
58
58
59
59
it ( 'outputs Number type by default' , ( ) => {
60
60
const component = Vue . extend ( {
61
+ components : { VueNumeric } ,
61
62
data : ( ) => ( { total : 100 } ) ,
62
63
template : '<div><vue-numeric v-model="total" :min="1" :max="100"></vue-numeric></div>' ,
63
- components : { VueNumeric }
64
64
} )
65
65
66
66
const wrapper = mount ( component )
@@ -69,9 +69,9 @@ describe('vue-numeric.vue', () => {
69
69
70
70
it ( 'outputs String if specified' , ( ) => {
71
71
const component = Vue . extend ( {
72
+ components : { VueNumeric } ,
72
73
data : ( ) => ( { total : 100 } ) ,
73
74
template : '<div><vue-numeric v-model="total" outputType="String" :min="1" :max="100"></vue-numeric></div>' ,
74
- components : { VueNumeric }
75
75
} )
76
76
77
77
const wrapper = mount ( component )
@@ -133,9 +133,9 @@ describe('vue-numeric.vue', () => {
133
133
134
134
it ( 'cannot exceed max props' , ( ) => {
135
135
const component = Vue . extend ( {
136
+ components : { VueNumeric } ,
136
137
data : ( ) => ( { total : 150 } ) ,
137
138
template : '<div><vue-numeric v-model="total" :max="100"></vue-numeric></div>' ,
138
- components : { VueNumeric }
139
139
} )
140
140
141
141
const wrapper = mount ( component )
@@ -144,9 +144,9 @@ describe('vue-numeric.vue', () => {
144
144
145
145
it ( 'cannot below min props' , ( ) => {
146
146
const component = Vue . extend ( {
147
+ components : { VueNumeric } ,
147
148
data : ( ) => ( { total : 150 } ) ,
148
149
template : '<div><vue-numeric v-model="total" :min="200"></vue-numeric></div>' ,
149
- components : { VueNumeric }
150
150
} )
151
151
152
152
const wrapper = mount ( component )
@@ -155,9 +155,9 @@ describe('vue-numeric.vue', () => {
155
155
156
156
it ( 'process valid value ' , ( ) => {
157
157
const component = Vue . extend ( {
158
+ components : { VueNumeric } ,
158
159
data : ( ) => ( { total : 100 } ) ,
159
160
template : '<div><vue-numeric v-model="total" :min="10" :max="200"></vue-numeric></div>' ,
160
- components : { VueNumeric }
161
161
} )
162
162
163
163
const wrapper = mount ( component )
@@ -166,9 +166,9 @@ describe('vue-numeric.vue', () => {
166
166
167
167
it ( 'allow minus value when minus props is true' , ( ) => {
168
168
const component = Vue . extend ( {
169
+ components : { VueNumeric } ,
169
170
data : ( ) => ( { total : - 150 } ) ,
170
171
template : '<div><vue-numeric v-model="total" :min="-150" :minus="true"></vue-numeric></div>' ,
171
- components : { VueNumeric }
172
172
} )
173
173
174
174
const wrapper = mount ( component )
@@ -177,9 +177,9 @@ describe('vue-numeric.vue', () => {
177
177
178
178
it ( 'disallow minus value when minus props is false' , ( ) => {
179
179
const component = Vue . extend ( {
180
+ components : { VueNumeric } ,
180
181
data : ( ) => ( { total : - 150 } ) ,
181
182
template : '<div><vue-numeric v-model="total" :min="-150" :minus="false"></vue-numeric></div>' ,
182
- components : { VueNumeric }
183
183
} )
184
184
185
185
const wrapper = mount ( component )
@@ -190,9 +190,9 @@ describe('vue-numeric.vue', () => {
190
190
const el = document . createElement ( 'div' )
191
191
const vm = new Vue ( {
192
192
el,
193
+ components : { VueNumeric } ,
193
194
data : ( ) => ( { total : 0 } ) ,
194
195
template : '<div><vue-numeric v-model="total"></vue-numeric></div>' ,
195
- components : { VueNumeric }
196
196
} ) . $mount ( )
197
197
198
198
setTimeout ( ( ) => {
@@ -216,10 +216,10 @@ describe('vue-numeric.vue', () => {
216
216
expect ( wrapper . data ( ) . amount ) . to . equal ( '2,000' )
217
217
} )
218
218
219
- it ( 'clear the field if zero value ' , ( ) => {
220
- const wrapper = mount ( VueNumeric , { propsData : { value : 0 , separator : '.' , precision : 2 } } )
219
+ it ( 'on focus empty string return empty string ' , ( ) => {
220
+ const wrapper = mount ( VueNumeric , { propsData : { value : '' , separator : '.' , precision : 2 } } )
221
221
wrapper . trigger ( 'focus' )
222
- expect ( wrapper . data ( ) . amount ) . to . equal ( null )
222
+ expect ( wrapper . data ( ) . amount ) . to . equal ( '' )
223
223
} )
224
224
225
225
it ( 'remove thousand separator and symbol on focus with , decimal' , ( ) => {
@@ -258,9 +258,9 @@ describe('vue-numeric.vue', () => {
258
258
259
259
it ( 'apply min props value if user input negative value when minus props disabled' , ( ) => {
260
260
const component = Vue . extend ( {
261
+ components : { VueNumeric } ,
261
262
data : ( ) => ( { total : - 200 } ) ,
262
263
template : '<div><vue-numeric v-model="total" :min="150" :minus="false"></vue-numeric></div>' ,
263
- components : { VueNumeric }
264
264
} )
265
265
266
266
const wrapper = mount ( component )
@@ -269,9 +269,9 @@ describe('vue-numeric.vue', () => {
269
269
270
270
it ( 'apply 0 value if user input negative value when minus props disabled and min props is negative too' , ( ) => {
271
271
const component = Vue . extend ( {
272
+ components : { VueNumeric } ,
272
273
data : ( ) => ( { total : - 200 } ) ,
273
274
template : '<div><vue-numeric v-model="total" :min="-150" :minus="false"></vue-numeric></div>' ,
274
- components : { VueNumeric }
275
275
} )
276
276
277
277
const wrapper = mount ( component )
@@ -307,14 +307,30 @@ describe('vue-numeric.vue', () => {
307
307
} )
308
308
expect ( wrapper . data ( ) . amount ) . to . equal ( '1 000,94' )
309
309
} )
310
+
310
311
it ( 'emit change event' , ( ) => {
311
312
const process = sinon . stub ( )
312
313
const wrapper = mount ( VueNumeric , { propsData : { value : 2000 } , methods : { process } } )
313
314
wrapper . trigger ( 'change' )
314
315
expect ( process . called ) . to . equal ( true )
315
316
} )
317
+
316
318
it ( 'initial value is 0 if zero is passed' , ( ) => {
317
319
const wrapper = mount ( VueNumeric , { propsData : { value : 0 } } )
318
320
expect ( wrapper . data ( ) . amount ) . to . equal ( '0' )
319
321
} )
322
+
323
+ it ( 'when format empty string should return empty string' , ( ) => {
324
+ const wrapper = mount ( VueNumeric , { propsData : { value : '' , separator : '.' , precision : 2 } } )
325
+ expect ( wrapper . vm . format ( '' ) ) . to . equal ( '' )
326
+ } )
327
+
328
+ it ( 'emit input event when process empty string' , ( ) => {
329
+ const update = sinon . stub ( )
330
+ const wrapper = mount ( VueNumeric , { propsData : { value : '' , separator : '.' , precision : 2 } , methods : { update } } )
331
+ const spy = sinon . spy ( wrapper . vm , '$emit' )
332
+ wrapper . trigger ( 'input' )
333
+ expect ( update . called ) . to . equal ( false )
334
+ expect ( spy . args [ 0 ] [ 0 ] ) . to . equal ( 'input' )
335
+ } )
320
336
} )
0 commit comments