Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
Unit testing for JavaScript in the context of a web application

I've done some research about this topic, and I think I know what to do. However, as per my understanding this requires confusing or complex configuration.

Objective:

Ability to perform unit testing for JavaScript code that is used within the context of a web application.

The JavaScript functions are deployed in script file and linked to the HTML page using traditional methods.

We need to used a simple Unit Testing Framework similar to Jest and avoid the need to get into Brower Control such as using Selenium WebDriver and the like.

The problem is Jest works with NodeJS and not sure how to make this work with front-end web application.

High-Level Approach:

Based on my research, it seems I have to keep the script used for the web application in a separate configuration of the test project. See example below:

//Main JavaScript used by HTML: sciprt.js
function addTwoNumbers(a, b) {
  return a+b;
}
...
...
other functions
...
...
<!DOCTYPE html>
<html>
<body>

<h1>The script src attribute</h1>

<script src="script.js">
</script>

</body>
...
...
</html>

Now let's say we need to used Jest to write test scripts, then we have to setup a NodeJS project which means we have to copy the script file script.js to the test project, and convert it to use JavaScript Modules.

I am trying to avoid this confusing setup, and looking for a method to write test scripts to use the same deployed parts of the web application without the need to mess around with files.

Another problem I will face is how to deal with functions that references HTML components? Those will not be available to NodeJS, correct? I believe this can be done by refactoring the code to become modular so that the functions to be tested will not reference web elements.

I appreciate your help to setup a test project and use the deployed script and avoid the need to do complex or confusing setup.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda