test(Form): add test case of trigger in rules

This commit is contained in:
陈嘉涵 2020-02-20 10:22:14 +08:00
parent 8cc09876d4
commit 9b70d1a4dc

View File

@ -219,3 +219,52 @@ test('validate-trigger - onChange', async () => {
await later(); await later();
expect(wrapper.contains('.van-field__error-message')).toBeTruthy(); expect(wrapper.contains('.van-field__error-message')).toBeTruthy();
}); });
test('validate-trigger - custom trigger in rules', async () => {
const wrapper = mountForm({
template: `
<van-form validate-trigger="none" ref="form">
<van-field name="A" :rules="rulesA" :value="valueA" />
<van-field name="B" :rules="rulesB" :value="valueB" />
</van-form>
`,
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);
});