import { mount } from '@vue/test-utils'; import { asyncExpect } from '@/tests/utils'; import Form from '..'; describe('Form', () => { it('should display two message', async () => { const rules = [ { pattern: /^\w+$/, message: 'Error message 1', }, { pattern: /^\w+$/, message: 'Error message 2', }, ]; let myForm; const Form1 = Form.create()({ render() { myForm = this.form; return (
{this.form.getFieldDecorator('account', { initialValue: '+=-/', rules })()}
); }, }); const wrapper = mount(Form1, { sync: false, }); await asyncExpect(()=>{ myForm.validateFields(); }); wrapper.vm.$forceUpdate(); expect(wrapper.html()).toMatchSnapshot(); }); it('should display custom message', () => { let myForm; const Form1 = Form.create()({ created() { myForm = this.form; }, render() { const rules = [ { pattern: /^$/, message: ( Account does not exist,{' '} Forgot account? ), }, ]; return (
{this.form.getFieldDecorator('account', { initialValue: 'antd', rules })()}
); }, }); const wrapper = mount(Form1); myForm.validateFields(); wrapper.vm.$forceUpdate(); expect(wrapper.html()).toMatchSnapshot(); }); });