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

133
Vistas
mocking document.domain and other objects in jest

I am trying to run tests in jest at the moment, at the moment I am getting an error that looks like this,

TypeError: Cannot read property 'indexOf' of undefined

      194 |     if (this.config.storage_host) {
      195 |       domain = this.config.storage_host;
    > 196 |     } else if (document.domain.indexOf("example") > 0) {
          |                                ^
      197 |       let domainParts: string[] = document.domain.split(".");
      198 |       domainParts.splice(0, 1);
      199 |       domain = domainParts.join(".");

The problem it would seem is that document.domain is undefined, how would I go about creating a document.domain for the tests? I assume I would mock it somehow, I have tried,

    Object.defineProperty(document, 'domain' {
        writable: true,
        value: 'https://www.example.com'
    });

but that did not make any change. I will also need to mock an object that is used throughout the application how would I go about that? The object is called ProvideState and has attributes like,

const ProvideState = {
    state: {
        app: 'client'
        context: '',
   }
}
about 4 years ago · Juan Pablo Isaza
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