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

143
Views
Probar funciones de promesas anidadas con el marco JEST

Mi ayudante de dinamo es así:

ayudante.ts

 export const save = async (order: TkOrderModel): Promise<void> => { const params = { ...defaultParams, ReturnValues: 'ALL_OLD', Item: order }; await docClient.put(params, async (err, data) => { if (err) return err; else return data; }).promise(); };

archivo de prueba:

 jest.mock('aws-sdk', () => { const fakePromise = { promise: jest.fn(), }; const mDocumentClient = { put: fakePromise.promise, }; const mDynamoDB = { DocumentClient: jest.fn(() => mDocumentClient) }; return { DynamoDB: mDynamoDB }; }); const mDynamoDb = new AWS.DynamoDB.DocumentClient(); const tableName = 'orders'; const defaultParams = { TableName: tableName, }; afterAll(() => { jest.resetAllMocks(); }); const fakePromise = { promise: jest.fn(), }; describe('dynamo helper', () => { test('should save items', async () => { const order = { cartId: 'any_cartId', orderId: 'any_orderId', }; const params = { ...defaultParams, ReturnValues: 'ALL_OLD', Item: order, }; const cb = fakePromise.promise.mockImplementation(() => Promise.resolve(order) ); mDynamoDb.put(params, cb); await orderRepository.save(order); expect(mDynamoDb.put).toBeCalledTimes(1); }); });

jest está devolviendo el siguiente error: TypeError: No se puede leer la propiedad 'promesa' de indefinido . ¿Necesito burlarme de la promesa de una manera diferente para no devolver este error de compilación? He intentado hacerlo de diferentes formas y no he tenido éxito. ¿Cualquier sugerencia?

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!