complete unit tests for input email component

This commit is contained in:
mahula 2023-01-04 20:27:42 +01:00
parent 6ad6e0e4fa
commit 19ec650496
2 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import InputEmail from './InputEmail' import InputEmail from './InputEmail'
import flushPromises from 'flush-promises'
const localVue = global.localVue const localVue = global.localVue
@ -60,10 +61,17 @@ describe('InputEmail', () => {
}) })
describe('input value changes', () => { describe('input value changes', () => {
it.skip('trims the email after blur', async () => {
await wrapper.find('input').setValue(' valid@email.com ')
await wrapper.find('input').trigger('blur')
await flushPromises()
expect(wrapper.vm.currentValue).toBe('valid@email.com')
})
it('emits input with new value', async () => { it('emits input with new value', async () => {
await wrapper.find('input').setValue('12') await wrapper.find('input').setValue('user@example.org')
expect(wrapper.emitted('input')).toBeTruthy() expect(wrapper.emitted('input')).toBeTruthy()
expect(wrapper.emitted('input')).toEqual([['12']]) expect(wrapper.emitted('input')).toEqual([['user@example.org']])
}) })
}) })
@ -73,5 +81,13 @@ describe('InputEmail', () => {
expect(wrapper.vm.currentValue).toEqual('user@example.org') expect(wrapper.vm.currentValue).toEqual('user@example.org')
}) })
}) })
describe('email normalization', () => {
it('is trimmed', async () => {
await wrapper.setData({ currentValue: ' valid@email.com ' })
wrapper.vm.normalizeEmail()
expect(wrapper.vm.currentValue).toBe('valid@email.com')
})
})
}) })
}) })

View File

@ -67,7 +67,7 @@ export default {
methods: { methods: {
normalizeEmail() { normalizeEmail() {
this.emailFocused = false this.emailFocused = false
this.form.email = this.form.email.trim() this.currentValue = this.currentValue.trim()
}, },
}, },
} }