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

178
Vistas
¿Cómo pruebo un constructor en Jasmine?

pingPongGame.js

 class PingPongGame { constructor(winningPoints) { this.playerOneScore = 0; this.playerTwoScore = 0; this.winningPoints = winningPoints; } get playerOneScore() { return this.playerOneScore; } set playerOneScore(newPlayerOneScore) { this.playerOneScore = newPlayerOneScore; } get playerTwoScore() { return this.playerTwoScore; } set playerTwoScore(newPlayerTwoScore) { this.playerTwoScore = newPlayerTwoScore; } get winningPoints() { return this.winningPoints; } set winningPoints(newWinningPoints) { this.winningPoints = newWinningPoints; } }

pingPongGame.spec.js

 describe("when the pingPongGame constructor is called", function () { it("should create a ping pong game with given arguments.", function () { let newPingPongGame = new PingPongGame(10); expect(newPingPongGame.getWinningPoints).toBe(10); }); });

Cuando ejecuto la prueba Jasmine anterior, aparece el siguiente error. Creo que podría necesitar burlarme de algo, ya que parece que hay algún tipo de recursión. ¿Alguien tiene sugerencias sobre cómo probar correctamente el constructor?

 when the pingPongGame constructor is called > should create a ping pong game with given arguments. RangeError: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29) at PingPongGame.set playerOneScore [as playerOneScore] (file:///C:/Users/charl/Documents/WebDev/PingPongScorekeeper/src/pingPongGame.js:13:29)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Está viendo un desbordamiento de pila porque los nombres de las propiedades de la instancia y los captadores/establecedores son idénticos. Debe usar un nombre diferente para sus propiedades internas para usar este enfoque. La convención generalmente es prefijar el nombre con un _ así...

 class PingPongGame { constructor(winningPoints) { //... this._winningPoints = winningPoints; } //... get winningPoints() { return this._winningPoints } set winningPoints(winningPoints) { this._winningPoints = winningPoints } }
about 4 years ago · Juan Pablo Isaza Denunciar
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