DEV Community

Jesse Warden
Jesse Warden

Posted on • Originally published at jessewarden.com

2

Alternative to AWS Mock

I don’t think you need AWS Mock to test your Lambdas.

If you think you need it, it’s because you’re using global variables, or state, should be using dependency injection via stubs instead.

This image from docs shows it overrides a global module import, then has to restore the global after the test has run. I get some people need/like before/after, but that is state-full, leads to tiring test setup, & accidental non-determinism in tests.

Lambda’s are stateless.

Instead, use pure functions + dependency inject your stubs (e.g. parameter to function). Also note, no need for Sinon or some other test double library. JavaScript is so good nowadays to easily make objects/classes/functions or any combination thereof on the fly that are terse.

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay