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

236
Views
Afirmación de prueba de broma, espere un objeto anidado

Cuando hago lo siguiente, espero en broma con la prueba nativa

 expect(mockOnChange).toHaveBeenCalledWith({ order_type: expect.arrayContaining(['1']), number: '', ouser_ids: expect.arrayContaining(['user_id1']), payment_type: expect.arrayContaining(['2']), start_date: old_Date, end_date: current_date, state: 'all', });

me sale el siguiente error

 Object { "end_date": "2022/06/07", "number": "", - "order_type": ArrayContaining [ + "order_type": Array [ "1", ], - "ouser_ids": ArrayContaining [ + "ouser_ids": Array [ "user_id1", - ], - "payment_type": ArrayContaining [ - "2", ], + "payment_type": Array [], "start_date": "2022/06/01", "state": "all", },

También lo intenté sin expect.arrayContaining() y sigo recibiendo el mismo error. ¿Estoy haciendo esto mal?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No puede usar expect.arrayContaining dentro de las propiedades de un objeto que está esperando. Deberá utilizar un enfoque alternativo de la siguiente manera:

 const objectCalledWith = mockOnChange.mock.calls[0][0]; expect(objectCalledWith.order_type).toEqual(expect.arrayContaining(['1'])); // and so on for the other property values...

Explicación:

mock.calls contiene todas las llamadas realizadas en mockOnChange , donde elegimos específicamente acceder a la primera llamada a través de [0] . El segundo [0] recupera el primer argumento con el que se llamó a la función mockOnChange y lo asignamos a la variable objectCalledWith . Luego podemos usar esta variable para inspeccionar y validar sus propiedades usando los comparadores expect según sea necesario.

about 4 years ago · Juan Pablo Isaza Report
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!