GitHub

@@ -190,6 +190,24 @@ describe('Form', () => {

190190

expect(passwordField.text()).toBe('')

191191

})

192192193+

test('setErrors with regex works', async () => {

194+

form.value.setErrors([{ id: 'emailInput', name: 'email', message: 'this is an error' }])

195+196+

expect(form.value.errors).toMatchObject([{ id: 'emailInput', name: 'email', message: 'this is an error' }])

197+198+

form.value.setErrors([{ id: 'passwordInput', name: 'password', message: 'this is another error' }], /email/)

199+200+

expect(form.value.errors).toMatchObject([{ id: 'passwordInput', name: 'password', message: 'this is another error' }])

201+202+

await nextTick()

203+204+

const emailField = wrapper.find('#emailField')

205+

expect(emailField.text()).toBe('')

206+207+

const passwordField = wrapper.find('#passwordField')

208+

expect(passwordField.text()).toBe('this is another error')

209+

})

210+193211

test('clear works', async () => {

194212

form.value.setErrors([{

195213

id: 'emailInput',

@@ -201,13 +219,57 @@ describe('Form', () => {

201219202220

expect(form.value.errors).toMatchObject([])

203221222+

await flushPromises()

223+204224

const emailField = wrapper.find('#emailField')

205225

expect(emailField.text()).toBe('')

206226207227

const passwordField = wrapper.find('#passwordField')

208228

expect(passwordField.text()).toBe('')

209229

})

210230231+

test('clear with name works', async () => {

232+

form.value.setErrors([

233+

{ id: 'emailInput', name: 'email', message: 'this is an error' },

234+

{ id: 'passwordInput', name: 'password', message: 'this is another error' }

235+

])

236+237+

form.value.clear('email')

238+239+

expect(form.value.errors).toMatchObject([

240+

{ id: 'passwordInput', name: 'password', message: 'this is another error' }

241+

])

242+243+

await nextTick()

244+245+

const emailField = wrapper.find('#emailField')

246+

expect(emailField.text()).toBe('')

247+248+

const passwordField = wrapper.find('#passwordField')

249+

expect(passwordField.text()).toBe('this is another error')

250+

})

251+252+

test('clear with regex works', async () => {

253+

form.value.setErrors([

254+

{ id: 'emailInput', name: 'email', message: 'this is an error' },

255+

{ id: 'passwordInput', name: 'password', message: 'this is another error' }

256+

])

257+258+

form.value.clear(/email/)

259+260+

expect(form.value.errors).toMatchObject([

261+

{ id: 'passwordInput', name: 'password', message: 'this is another error' }

262+

])

263+264+

await nextTick()

265+266+

const emailField = wrapper.find('#emailField')

267+

expect(emailField.text()).toBe('')

268+269+

const passwordField = wrapper.find('#passwordField')

270+

expect(passwordField.text()).toBe('this is another error')

271+

})

272+211273

test('submit error works', async () => {

212274

await form.value.submit()

213275

@@ -272,6 +334,15 @@ describe('Form', () => {

272334

])

273335

})

274336337+

test('getErrors with regex works', async () => {

338+

await form.value.submit()

339+

const errors = form.value.getErrors(/email/)

340+341+

expect(errors).toMatchObject([

342+

{ id: 'emailInput', name: 'email', message: 'Invalid input: expected string, received undefined' }

343+

])

344+

})

345+275346

test('touchedFields works', async () => {

276347

const emailInput = wrapper.find('#emailInput')

277348

Read the original on github.com ↗