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

100
Views
afterEach Jest no borra mi puntaje total

Por alguna razón estoy recibiendo:

Pasa la primera prueba: "Amar a todos"

2da prueba falla: Esperado: "Quince amor" Recibido: "Quince amorAmar a todos"

Según tengo entendido, necesito usar afterEach para derribar la configuración original. He intentado esto pero no parece 'borrar' el totalScore.

¡Gracias por tu ayuda!

Archivo de prueba:

 const Tennis = require("../src/index"); describe("Tennis game", () => { let tennis; beforeEach(() => { tennis = new Tennis(); }); afterEach(() => { tennis.resetGame(); }); const scoreShouldBe = (expected) => { tennis.getScore(); expect(tennis.totalScore).toBe(expected); }; test("Love all", () => { scoreShouldBe("Love all"); }); test("Fifteen love", () => { tennis.firstPlayerScore(); scoreShouldBe("Fifteen love"); }); });

Archivo index.js:

 class Tennis { constructor() { this.firstPlayerScoreTimes = 0; this.totalScore = ""; } getScore() { if (this.firstPlayerScoreTimes === 1) { this.totalScore += "Fifteen love"; } this.totalScore += "Love all"; } firstPlayerScore() { this.firstPlayerScoreTimes++; } resetGame() { this.totalScore = ""; } } module.exports = Tennis;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Su prueba está funcionando bien, lo que necesita actualizar es su código de producción.

La lógica actual, cuando firstPlayerScoreTimes es 1, establece el puntaje como Fifteen love y también agrega Love all string al puntaje. Supongo que este no es su requisito. Actualicemos la función getScore :

 getScore() { if (this.firstPlayerScoreTimes === 1) { return this.totalScore += "Fifteen love"; // stop, that's enough } this.totalScore += "Love all"; }
about 4 years ago · Juan Pablo Isaza Report

0

Elimine += en su método getScore en la clase Tennis , ya que agregará la nueva cadena a la cadena anterior.

 class Tennis { constructor() { this.firstPlayerScoreTimes = 0; this.totalScore = ""; } getScore() { if (this.firstPlayerScoreTimes === 1) { this.totalScore = "Fifteen love"; } this.totalScore = "Love all"; } firstPlayerScore() { this.firstPlayerScoreTimes++; } resetGame() { this.totalScore = ""; } } module.exports = Tennis;
about 4 years ago · Juan Pablo Isaza 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!