Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
¿Cómo probar javascript en node repl (sin navegador)?

Tengo 2 archivos mycode.js y mycode.test.js . Quiero probarlo en la consola Node (repl) - (sin navegador), en estilo karma.

micódigo.prueba.js

 var expect = require('expect'); var mycode = require("./mycode"); describe("mycode", () => { it("should properly run tests", () => { expect(1).toBe(1); }); });

¿Cuál es la configuración más simple posible para lograr esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No sé cómo podría hacer que eso funcione en el nodo repl porque una llamada a require() asume que carga esa función por separado, antes de cargar el archivo que desea probar. La única forma que veo de probar el código en la réplica es tener la función que está usando para probar incluida en el archivo cargado. Por ejemplo, para probar cómo funciona la anulación de funciones, puede crear function_override.js y luego cargarlo en el repl --

$ .load path/to/file/function_override.js

-- y tener una función de afirmación () que se usa para probar la salida de otras funciones dentro de ese archivo. P.ej:

 function assert(value, text) { if (value === true) { console.log(text); } else { console.log ("that is false"); } } var fun = 3; function FuncType1(){ assert(typeof fun === "function", "We access the function"); } function FuncType2(){ var fun = 3; assert(typeof fun === "number", "Now we access the number"); } function FuncType3(){ assert(typeof fun === "number", "Still a number"); } function fun(){}; FuncType1(); // returns "We access the function" FuncType2(); // returns "Now we access the number" FuncType3(); // returns "that is false"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!