diff --git a/src/form/test/props.spec.js b/src/form/test/props.spec.js index 15f8409b8..88460f98c 100644 --- a/src/form/test/props.spec.js +++ b/src/form/test/props.spec.js @@ -219,3 +219,52 @@ test('validate-trigger - onChange', async () => { await later(); expect(wrapper.contains('.van-field__error-message')).toBeTruthy(); }); + +test('validate-trigger - custom trigger in rules', async () => { + const wrapper = mountForm({ + template: ` + + + + + `, + data() { + return { + valueA: '', + valueB: '', + rulesA: [ + { + message: 'A', + required: true, + trigger: 'onChange', + }, + ], + rulesB: [ + { + message: 'B', + required: true, + trigger: 'onBlur', + }, + ], + }; + }, + }); + + const inputs = wrapper.findAll('input'); + + inputs.at(0).trigger('blur'); + wrapper.setData({ valueB: '1' }); + await later(); + wrapper.setData({ valueB: '' }); + await later(); + expect(wrapper.contains('.van-field__error-message')).toBeFalsy(); + + inputs.at(1).trigger('blur'); + wrapper.setData({ valueA: '1' }); + await later(); + wrapper.setData({ valueA: '' }); + await later(); + expect( + wrapper.element.querySelectorAll('.van-field__error-message').length + ).toEqual(2); +});