Tengo una función contenedora defer que retrasa la implementación de cualquier otra función:
const playerPerformance = { goals: 33, assists: 21, points(penaltiesEarned) { console.log((this.goals * 2) + (this.assists * 1.5) + (penaltiesEarned * 1.5)); }, }; const defer = (func, ms) => { return function() { setTimeout(() => func.call(this, ...arguments), ms); }; }; const deferredPointsDisplay = defer(playerPerformance.points, 1000); deferredPointsDisplay.call( { goals: 18, assists: 19 }, 7); // 75Quiero ejecutar una prueba unitaria que probará qué datos se registran en una consola, pero no tomo el control del temporizador, por lo que se aprobará la prueba.
it('should return 75', () => { const playerPerformance = { goals: 33, assists: 21, points(penaltiesEarned) { console.log((this.goals * 2) + (this.assists * 1.5) + (penaltiesEarned * 1.5)); }, }; const consoleSpy = jest.spyOn(console, 'log'); const deferredPointsDisplay = defer(playerPerformance.points, 1000); deferredPointsDisplay.call( { goals: 18, assists: 19 }, 7); expect(consoleSpy).toHaveBeenCalledWith(75); });Por favor, ayúdame a desarrollar esta prueba unitaria para pasar la prueba.