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

757
Vistas
How can jest test a function that uses performance.getEntries()?

When running jest, if a function makes use of performance.getEntries (or performance.getEntriesByName) then the test throws an exception:

performance.getEntries is not a function

How can I allow my tests to continue running without crashing?


According to the documentation, performance.getEntries was removed from perf_hooks in NodeJS v10.0.0 (https://github.com/nodejs/node/pull/19563) and the same functionality may be achieved using

const measures = []
const obs = new PerformanceObserver(list => {
  measures.push(...list.getEntries())
  obs.disconnect()
})
obs.observe({entryTypes: ['measure']})
function getEntriesByType(name) {
  return measures
}

However the above solution is only viable when working directly in the NodeJS application, not when running tests as I do not want to change my implementation. I have tried mocking performance.getEntries as a global in setupAfterEnv, as I would for other globals. For example:

global.performance = {
  getEntries: () => []
}

However when debugging, performance is always equal to {} (while performance.now() works well. I believe this is default jsdom (which is my testEnvironment).

over 4 years ago · Santiago Trujillo
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