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

346
Views
Jest pasa en un archivo, pero falla en otro archivo

Tengo un programa js muy simple en un archivo llamado Task2.js, donde se usa una función processInput(date) para procesar la entrada del usuario. He escrito algunas pruebas básicas para ello, pero la mayoría de ellas fallaron con mensajes inesperados. Escribí todas esas pruebas en el archivo Task2.test.js. Cuando muevo las pruebas que fallan de Task2.test.js a Task2.js y vuelvo a ejecutar jest, todas pasan. No tengo idea de por qué funcionan en un archivo, pero no en el otro.

Tarea2.js:

 function processInput(date){ if(date.trim() == "quit"){ rl.close(); throw new Error("User requested quit"); } // Trim trailing spaces and then split into three variables try{ // Regex that matches any year starting with 1-9, any month between 1-12, and any day between 1-31 if(!(/^\s*[1-9]\d*\s+([1-9]|1[0-2])\s+([1-9]|[1-2][0-9]|3[01])\s*$/.test(date))){ console.log("Invalid input, please try again"); return false; }; [y, m, d] = date.trim().split(/\s+/); } catch(error){ console.log("Invalid input, please try again"); return false; } return [y, m, d]; }

Algunas pruebas en Task2.test.js:

 const processInput = require("./Task2"); test("TestQuit", () => { expect(() => processInput("quit")).toThrow(); }); test("TestInvalidInput", () => { expect(processInput(" 2021 13 13 ")).toBeFalsy(); });

Esto es lo que devuelven esas pruebas cuando se ejecutan en Task2.test.js:

 TestQuit expect(received).toThrow() Received function did not throw TestInvalidInput expect(received).toBeFalsy() Received: " 2021 13 13 undefined NaN"
about 4 years ago · Juan Pablo Isaza
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!