Skip to content

Commit 5a6e946

Browse files
subtronicRodionov Maxim
and
Rodionov Maxim
authored
Test and lint for emit change event (#94)
Co-authored-by: Rodionov Maxim <m.rodionov@corp.mail.ru>
1 parent dcf4e98 commit 5a6e946

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/vue-numeric.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<template>
22
<input
3+
v-if="!readOnly"
4+
ref="numeric"
35
:placeholder="placeholder"
6+
v-model="amount"
7+
type="tel"
48
@blur="onBlurHandler"
59
@input="onInputHandler"
610
@focus="onFocusHandler"
7-
ref="numeric"
8-
type="tel"
9-
v-model="amount"
10-
v-if="!readOnly"
11+
@change="onChangeHandler"
1112
>
1213
<span
1314
v-else
@@ -283,6 +284,13 @@ export default {
283284
},
284285
285286
methods: {
287+
/**
288+
* Handle change event.
289+
* @param {Object} e
290+
*/
291+
onChangeHandler (e) {
292+
this.$emit('change', e)
293+
},
286294
/**
287295
* Handle blur event.
288296
* @param {Object} e

test/specs/vue-numeric.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,10 @@ describe('vue-numeric.vue', () => {
285285
})
286286
expect(wrapper.data().amount).to.equal('1 000,94')
287287
})
288+
it('emit change event', () => {
289+
const process = sinon.stub()
290+
const wrapper = mount(VueNumeric, { propsData: { value: 2000 }, methods: { process }})
291+
wrapper.trigger('change')
292+
expect(process.called).to.equal(true)
293+
})
288294
})

0 commit comments

Comments
 (0)