You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and I would like to test the handler mocking .use(ssm({...})) with jest.
First I was fighting with Jest and ESM module setup and I finally I get to the point where I was thinking to mock getInternal function in the following way:
But from this error, it looks like the original implementation of getInternal is called (not my mock). I have no idea why.
Error: Failed to resolve internal values
at getInternal (/Users/jgi/Development/my_project/node_modules/@middy/util/index.js:83:11)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at async ssmMiddlewareBefore (/Users/jgi/Development/my_project/node_modules/@middy/ssm/index.js:181:20)
at async runMiddlewares (/Users/jgi/Development/my_project/node_modules/@middy/core/index.js:230:17)
at async runRequest (/Users/jgi/Development/my_project/node_modules/@middy/core/index.js:154:5)
at async Object.<anonymous> (/Users/jgi/Development/my_project/lambdas/middy-router/src/__tests__/handler.test.ts:76:20) {
[cause]: { package: '@middy/util', data: [ [CredentialsProviderError] ] }
}
Do you guys have any example how to properly test Middy handler with mocking selected use middleware?
Any help and examples will be much appreciated.
Best wishes
JGI
The text was updated successfully, but these errors were encountered:
jgilewski-kone
changed the title
How to test Middy handler with mocking middleware using Jest?
How to test Middy handler with mocked middleware using Jest?
Feb 4, 2025
Sorry to hear you're having troubles. I don't personally use jest, so I can't help there. But, if you take a look at the unit tests for middlewares like ssm, you'll see that the tests mock the AWS Client using aws-sdk-client-mock.
I tried that too. ssm midleware is initializing the middleware in the tests so they can provide mocked AwsClient (as here) from aws-sdk-client-mock.
My ssm middleware is already configured in the handler I tested and is not using the mocked client.
Hi,
I have a folloiwng handler:
and I would like to test the handler mocking
.use(ssm({...}))
with jest.First I was fighting with Jest and ESM module setup and I finally I get to the point where I was thinking to mock
getInternal
function in the following way:But from this error, it looks like the original implementation of
getInternal
is called (not my mock). I have no idea why.Do you guys have any example how to properly test Middy handler with mocking selected
use
middleware?Any help and examples will be much appreciated.
Best wishes
JGI
The text was updated successfully, but these errors were encountered: