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

416
Views
Intentar crear un código auxiliar en una función da como resultado que el Descriptor de la propiedad no sea configurable ni escribible

Estoy tratando de escribir una prueba unitaria que bloquee la función getSignedUrl del paquete @aws-sdk/s3-request-presigner , sin embargo, cuando intento bloquear la función con sinon , recibo el error:

  • TypeError: el descriptor de la propiedad getSignedUrl no es configurable ni escribible
 const s3RequestSigner = require("@aws-sdk/s3-request-presigner"); const expect = require('chai').expect; const sinon = require('sinon') .... it('should throw an error when getSignedUrl rejects', async function() { const sandbox = sinon.createSandbox(); sandbox.stub(s3RequestSigner, "getSignedUrl").rejects("fakeUrl"); sandbox.restore(); })

Estoy usando node.js 16 y escribo javascript en lugar de mecanografiado. ¿Hay alguna manera de simular mi función? De lo contrario, estoy luchando para escribir mis pruebas.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Así que no haré de esta la respuesta oficial, a menos que no haya mejores soluciones, pero esto es lo que mi investigación ha dado como resultado.

El problema está relacionado con esto: https://github.com/sinonjs/sinon/issues/2377

Donde sinon arrojará un error cuando Object.descriptor no sea configurable.

No hay una forma obvia de evitar eso actualmente, que pueda encontrar. La forma de resolverlo es usar proxyquire:

 const sinon = require('sinon') const proxyquire = require('proxyquire') ... it('should throw an error when getSignedUrl rejects', async function() { const fakeurl = 'hello world' const fakeURL = sinon.stub().resolves(fakeurl) const handler = proxyquire( '../../handlers/presigned_url', { '@aws-sdk/s3-request-presigner': { 'getSignedUrl': async () => { return fakeURL() } } } )

Esto luego se resolverá con lo que quieras que sea fakeurl .

about 4 years ago · Santiago Gelvez 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!