Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
How to run mocha script to test url via browser (without using XMLHttpRequest)

Hello: though new to nodejs and mocha and seek your help. Thank You in advance.

I am trying to run a simple mocha test via the browser (not the terminal) to access a url and get the response status.

Using XMLHttpRequest it works. However, i want to use a node library (say request.js). For testing mocha script from browser i am unable to find how load request.js correctly. Please help.

test.js (using XMLHttpRequest)

describe('suite', function(){

    it('case using XMLHTTPREQUEST', function(done){        
        var url = "http://oss.sheetjs.com/js-xlsx/test_files/formula_stress_test_ajax.xlsx";
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.onload = function (e) {
            console.log("TEST RESPONSE STATUS IS: " + xhr.status);
        }
        xhr.send();
        done();
    });

    it('case using AXIOS', function(done){        
        axios.get('http://www.google.com').then(
            function(response){
                    console.log(response.status);
                    done();
            });
    });
});

testrunner.html

<!DOCTYPE html>
<html>
<head>
  <title>Mocha Tests</title>
  <link rel="stylesheet" href="../node_modules/mocha/mocha.css">
</head>

<body>
  <div id="mocha"></div>
  <script src="../node_modules/axios/dist/axios.js"></script>
  <script src="../node_modules/mocha/mocha.js"></script>
  <script>mocha.setup('bdd')</script>
  <script src="./test.js"></script>
  <script>
    mocha.run()
  </script>
</body>    
</html>
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda