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

169
Vistas
Why expect({"[\"": 2}).toHaveProperty("[\"") is not true in jest?

I would like to test that object has a property with the name ["

In node js I can definie object "x" with property "[\""

> x = {"[\"": 2}
{ '["': 2 }
> x["[\""]
2

and of course

> '["' ===  "[\""
true

but when I typed test

expect({"[\"": 2}).toHaveProperty("[\"")

I received error:

Error: expect(received).toHaveProperty(path)

Expected path: "[\""
Received path: []

Received value: {"[\"": 2}

These versions also not works

expect({"[\"": 2}).toHaveProperty(`["`);
const p = `["`;
expect({[p]: 2}).toHaveProperty(p);

Update 1

There was a hypothesis that it is because of libraries

"esbuild-jest": "^0.5.0",
"esbuild-node-tsc": "^1.8.5",
"jest-text-transformer": "^1.0.2",

But I created pure js project with only jest@^27.5.1 installed and reproduced it

enter image description here

Update 2

There was a hypothesis that it depends on the operating system. I reproduced it on Macbook Pro and Arch Linux. For node js versions 12, 14, 16.

Working workaround:

expect({"[\"": 2}[`["`]).toBeDefined();
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