Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!