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

154
Vistas
Unit Testing a Function with embedded Async Function using Jest

I am trying to unit test this function

getSoapClient(url, wsdlOptions) {
        return soap.createClientAsync(url, wsdlOptions).catch((err) => {
            if (err.message.includes('Invalid WSDL URL')) {
                throw new SOAPFaultClientErrorException('Invalid WSDL URL', 555);
            } else if (err.message.includes('getaddrinfo ENOTFOUND incorrect')) {
                throw new AddressNotFoundException('Address Not Found', 400);
            }
        })
    }

I am using jest and trying to mock the catch block for when the url is incorrect.

it('getSoapClient throws a SOAPFaultClientErrorException if the WSDL is invalid', (done)=> {
        soap.createClientAsync = jest.fn().mockImplementation( () => { throw new SOAPFaultClientErrorException('Invalid WSDL URL', 555)})
        soap.createClientAsync(incorrectUrl, wsdlOptions).catch(err=> {
          expect(err).toBe(new SOAPFaultClientErrorException('Invalid WSDL URL', 555))
        })
        done()
      })

This is not working and I'm getting an error when trying to mock the implementation.

I'm not sure why it is throwing an error in the test(it just highlights the mockImplementation line with a red arrow under new).

I tried jest.spyOn and that also gives me the same error.

enter image description here

How do I mock the throwing of an error from soap.createClientAsync and test that it is throwing an error.

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