[improvement] Field: add clear event (#1944)

This commit is contained in:
neverland
2018-10-17 13:14:07 +08:00
committed by GitHub
parent fcd5a53cf7
commit 995ae8c300
5 changed files with 65 additions and 1 deletions
@@ -1,5 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`clearable 1`] = `
<div class="van-cell van-field">
<!---->
<!---->
<div class="van-cell__value van-cell__value--alone">
<div class="van-field__body">
<input type="text" class="van-field__control">
<!---->
<!---->
<!---->
</div>
<!---->
</div>
<!---->
</div>
`;
exports[`clearable 2`] = `
<div class="van-cell van-field">
<!---->
<!---->
<div class="van-cell__value van-cell__value--alone">
<div class="van-field__body">
<input type="text" class="van-field__control">
<i class="van-icon van-icon-clear van-field__clear">
<!---->
</i>
<!---->
<!---->
</div>
<!---->
</div>
<!---->
</div>
`;
exports[`render textarea 1`] = `
<div class="van-cell van-field">
<!---->
+18
View File
@@ -131,3 +131,21 @@ test('maxlength', async() => {
expect(input.element.value).toEqual('123');
expect(wrapper.emitted('input')[0][0]).toEqual('123');
});
test('clearable', () => {
const wrapper = mount(Field, {
propsData: {
value: 'test',
clearable: true
}
});
expect(wrapper).toMatchSnapshot();
const input = wrapper.find('input');
input.trigger('focus');
expect(wrapper).toMatchSnapshot();
wrapper.find('.van-field__clear').trigger('touchstart');
expect(wrapper.emitted('input')[0][0]).toEqual('');
expect(wrapper.emitted('clear')).toBeTruthy();
});