feat(Form): add scroll-to-error prop (#5680)

This commit is contained in:
陈嘉涵
2020-02-20 20:15:29 +08:00
parent a83082f599
commit b8818cef8c
4 changed files with 29 additions and 5 deletions
+18 -1
View File
@@ -1,4 +1,4 @@
import { later } from '../../../test';
import { later, mockScrollIntoView } from '../../../test';
import { mountForm, submitForm, getSimpleRules } from './shared';
test('rules prop - execute order', async () => {
@@ -268,3 +268,20 @@ test('validate-trigger - custom trigger in rules', async () => {
wrapper.element.querySelectorAll('.van-field__error-message').length
).toEqual(2);
});
test('scroll-to-error prop', async () => {
const fn = mockScrollIntoView();
const wrapper = mountForm({
template: `
<van-form scroll-to-error>
<van-field name="A" :rules="rulesA" value="" />
<van-button native-type="submit" />
</van-form>
`,
data: getSimpleRules,
});
await submitForm(wrapper);
expect(fn).toHaveBeenCalledTimes(1);
});