feat(Form): support rule formatter

This commit is contained in:
陈嘉涵
2020-02-23 19:56:44 +08:00
parent e48e5d47cd
commit d878354ebf
4 changed files with 52 additions and 17 deletions
+29
View File
@@ -59,6 +59,35 @@ test('rules prop - pattern', async () => {
});
});
test('rules prop - formatter', async () => {
const onFailed = jest.fn();
const wrapper = mountForm({
template: `
<van-form @failed="onFailed">
<van-field name="A" :rules="rules" value=" " />
<van-button native-type="submit" />
</van-form>
`,
data() {
return {
rules: [
{ required: true, formatter: val => val.trim(), message: 'foo' },
],
};
},
methods: {
onFailed,
},
});
await submitForm(wrapper);
expect(onFailed).toHaveBeenCalledWith({
errors: [{ message: 'foo', name: 'A' }],
values: { A: ' ' },
});
});
test('rules prop - async validator', async () => {
const onFailed = jest.fn();
const wrapper = mountForm({