mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
test(Form): add test case of trigger in rules
This commit is contained in:
parent
8cc09876d4
commit
9b70d1a4dc
@ -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);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user