jeudi 18 juin 2020

Unit Testing UI-related functions

I'm trying to get unit-testing concept and get lost with testing UI-related functions, like this:

const hideElem = elem => {
  elem.classList.add('js-hidden')
}

or this:

const getInputValue = (inputElem) => {
  let inputEl = document.querySelector(inputElem)

  return inputEl.value
}

or this:

const cleanInput = input => {
  const inputEl = document.querySelector(input)
  inputEl.value = ''
}

Do I need to cover such functions with unit tests in Jest? If yes - could you please explain how to combine here Jest and DOM-related things?

Aucun commentaire:

Enregistrer un commentaire