[new feature] NumberKeyboard: add maxlength prop (#3532)

This commit is contained in:
neverland
2019-06-17 15:33:25 +08:00
committed by GitHub
parent ce3dfc859a
commit 8331b7597d
6 changed files with 34 additions and 4 deletions

View File

@@ -127,7 +127,7 @@ test('focus on key', () => {
expect(wrapper).toMatchSnapshot();
});
test('controlled mode', () => {
test('bind value', () => {
const wrapper = mount(NumberKeyboard, {
propsData: {
value: ''
@@ -148,3 +148,26 @@ test('controlled mode', () => {
keys.at(11).trigger('click');
expect(wrapper.vm.value).toEqual('1');
});
test('maxlength', () => {
const onInput = jest.fn();
const wrapper = mount(NumberKeyboard, {
propsData: {
value: '',
maxlength: 1
},
listeners: {
input: onInput,
'update:value': value => {
wrapper.setProps({ value });
}
}
});
const keys = wrapper.findAll('.van-key');
keys.at(0).trigger('click');
keys.at(1).trigger('click');
expect(wrapper.vm.value).toEqual('1');
expect(onInput).toHaveBeenCalledTimes(1);
});