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

165
Vistas
Result should contain one of the correct answers

I am trying to write a test to see that the result returned from a function I am testing, is one of the correct results.

The result is an array of objects, for example [{ op: 'replace', path: '', value: { 0: 1 } }]

I want to see if this result is one of the correct answers, the test should pass.

I tried changing one of the tests as mentioned here, but I can't seem to get it to work.

Here is a code snippet:

 test(`For arrays, if data gets added, replace operation is sent`, () => {
      const data = []
      const update = [1]

      const result = functionToTest(data, update)

      const correct = [{ op: 'replace', path: '', value: { 0: 1 } }]
      const correct2 = [{ op: 'replace', path: '', value: [1] }]
      
//the result should include one of there answers. So if correct or correct 2 
//matches, it should pass.

//here I add all the correct answers to an array, to its essensially an 
//array of arrays
// [ 
//   [{ op: 'replace', path: '', value: { 0: 1 } }], 
//   [{ op: 'replace', path: '', value: [1] }]
// ]`
      const correctResults = [correct, correct2]

//the result of the function should be contained in one of the correct results
      expect(result).toEqual(
        expect.arrayContaining(correctResults)
      )
    })

I will write a code sandbox or something to test it in the browser. Here is the repo for now: https://github.com/jpbnetley/test-json-patch/tree/bugfix/update-tests

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have found that this seems to fix the problem.

    test(`For arrays, if data gets added, replace operation is sent`, () => {
      const data = []
      const update = [1]

      const result = functionToTest(data, update)

      const correct = [{ op: 'replace', path: '', value: { 0: 1 } }]
      const correct2 = [{ op: 'replace', path: '', value: [1] }]
      const correctResults = {...correct, ...correct2}

      expect(result).toEqual(
        expect.objectContaining(correctResults)
      )
    })
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