How to Mock AWS SDK v3 in Vitest Without Extra Dependencies

https://hackernoon.imgix.net/images/GKMDC80avThn4WCIH2KxmeCMx9o1-5t92bst.png

You're writing your tests, your AI agent is crushing it, all use cases and edge ones are being covered, but you've installed an AWS SDK and now you'll need to mock it (oh boy). After a few hours in, and a few years of life out the window, you notice that nothing you do can actually mock the cretin and you begin to lose hope, but after doing some research you soon notice that you'll need another dependency just for that: aws-sdk-client-mock. It surely gives you a convenient way to mock the clients, but it also makes them require special treatment, since it enforces a specific way of mocking. The good thing is, it does not need to be like this.

The traditional way

The usual approach with this library is to create a mock for the client class, implement the responses and reset it before each test.

import 'aws-sdk-client-mock-jest/vitest';import...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more