feat(Form): support pattern rule (#5700)

This commit is contained in:
陈嘉涵
2020-02-21 17:11:22 +08:00
parent 5d0a1304bc
commit 529e117096
6 changed files with 143 additions and 92 deletions
+27
View File
@@ -32,6 +32,33 @@ test('rules prop - execute order', async () => {
});
});
test('rules prop - pattern', async () => {
const onFailed = jest.fn();
const wrapper = mountForm({
template: `
<van-form @failed="onFailed">
<van-field name="A" :rules="rules" value="123" />
<van-button native-type="submit" />
</van-form>
`,
data() {
return {
rules: [{ pattern: /\d{6}/, message: 'foo' }],
};
},
methods: {
onFailed,
},
});
await submitForm(wrapper);
expect(onFailed).toHaveBeenCalledWith({
errors: [{ message: 'foo', name: 'A' }],
values: { A: '123' },
});
});
test('rules prop - async validator', async () => {
const onFailed = jest.fn();
const wrapper = mountForm({