Skip to content

Commit

Permalink
fix: test correction to throw error in form-values.test
Browse files Browse the repository at this point in the history
  • Loading branch information
milenacrios committed Feb 23, 2024
1 parent 712d8bb commit 41e2777
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/common/utils/tests/form-values.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,41 @@ describe('getFormValues', () => {
expect(formValue.expirationDate).toBe('')
expect(formValue.cvv).toBe('')
})
test('should be possible to return error if the elements are not found', async () => {
const {
form,
holderNameInput,
cvvInput,
expirationDateInput,
numberInput,
} = handleFormMock()

form.setAttribute(formElementsMock.form, '')
holderNameInput.setAttribute(formElementsMock.holderName, '')
numberInput.setAttribute(formElementsMock.number, '')
cvvInput.setAttribute(formElementsMock.cvv, '')
expirationDateInput.setAttribute(formElementsMock.expirationDate, '')

document.body.appendChild(form)
form.appendChild(holderNameInput)
form.appendChild(numberInput)
form.appendChild(expirationDateInput)
form.appendChild(cvvInput)

const inputs = document.querySelectorAll('input')
inputs[0].value = formValuesMock.holderName
inputs[1].value = formValuesMock.number
inputs[2].value = formValuesMock.expirationDate
inputs[3].value = formValuesMock.cvv

expect(() =>
getFormValues({
form: 'data-malga-form',
holderName: 'data-malga-holder-name',
number: 'data-malga-number',
expirationDate: 'data-malga-expiration-date',
cvv: 'data-malga-cvv',
}),
).toThrowError()
})
})

0 comments on commit 41e2777

Please sign in to comment.