fix(Stepper): change event emitted twice (#7820)

This commit is contained in:
neverland 2020-12-26 15:09:57 +08:00 committed by GitHub
parent 97509a90b1
commit b89832c03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -193,6 +193,11 @@ export default createComponent({
event.target.value = formatted; event.target.value = formatted;
} }
// perfer number type
if (formatted === String(+formatted)) {
formatted = +formatted;
}
this.emitChange(formatted); this.emitChange(formatted);
}, },

View File

@ -125,7 +125,7 @@ test('filter value during user input', () => {
input.element.value = '2'; input.element.value = '2';
input.trigger('input'); input.trigger('input');
expect(input.element.value).toEqual('2'); expect(input.element.value).toEqual('2');
expect(wrapper.emitted('input')[1][0]).toEqual('2'); expect(wrapper.emitted('input')[1][0]).toEqual(2);
}); });
test('shoud watch value and format it', () => { test('shoud watch value and format it', () => {
@ -149,12 +149,11 @@ test('only allow interger', () => {
}); });
const input = wrapper.find('input'); const input = wrapper.find('input');
input.element.value = '1.2'; input.element.value = '2.2';
input.trigger('input'); input.trigger('input');
input.trigger('blur'); input.trigger('blur');
expect(wrapper.emitted('input')[0][0]).toEqual('1'); expect(wrapper.emitted('input')[0][0]).toEqual(2);
expect(wrapper.emitted('input')[1][0]).toEqual(1);
}); });
test('input invalid value and blur', () => { test('input invalid value and blur', () => {
@ -246,8 +245,8 @@ test('async-change prop', () => {
input.element.value = '3'; input.element.value = '3';
input.trigger('input'); input.trigger('input');
expect(wrapper.emitted('input')[1][0]).toEqual('3'); expect(wrapper.emitted('input')[1][0]).toEqual(3);
expect(wrapper.emitted('change')[1][0]).toEqual('3'); expect(wrapper.emitted('change')[1][0]).toEqual(3);
}); });
test('min value is 0', () => { test('min value is 0', () => {