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

633
Vistas
How to substitute the PointerEvent in Jest? (PointerEvent is not defined)

Problem

In my react app I test for different event constructors in a switch case statement. Something like that:

switch (event.constructor) {
    case String:
        doSomething()
        break;
    case Array:
        doSomething()
        break;
    case Date:
        doSomething()
        break;
    case PointerEvent:
        doSomething()
        break;
    default:
        doSomething()
        break;

If I test this setup with jest it always throws me the error ReferenceError: PointerEvent is not defined. I can fix this problem by setting PointerEvent to window.PointerEvent. But the event in my jest environment has the type MouseEvent.

Question

How can I set the PointerEvent as an alias for the MouseEvent during testing? Or is there even a way to import an execute a PointerEvent in jest?

System

"@mui/material": "^5.6.3",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you look at this issue, you can see that jsdom appears to not implement PointerEvent

You can work around this this though

class MockPointerEvent {}

describe("PointerEvent", () => {
  beforeEach(() => {
    global.window.PointerEvent = MockPointerEvent as any;
  });

  it("confirms pointer event", () => {
    const pointerEvent = new PointerEvent("");

    expect(pointerEvent).toBeTruthy();
  });
});
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