Have someone unit testing examples using SST + Gra...
# sst
d
Have someone unit testing examples using SST + GraphQL + AppSyncApi ?
f
Hey @Daniela Vaz, r u looking to unit test ur CDK code?
I have used this tutorial
I would like to implement the unit testing for all GraphQL
f
Ah I see… so you mean unit tests for your Lambda code
d
Yes
f
I’m not familiar with unit testing GraphQL, but for Lambda functions in general, I try to put all the business logic in side effect free functions that aren’t making AWS calls, and just unit test those functions.
I’ve seen ppl mocking the AWS sdk in unit test too.
I don’t have any GraphQL specific tips 😌
d
Can you share some example with lambda functions ? It might help
j
We would need to put this together as an example but are you familiar with using Jest? https://jestjs.io You can add those tests in the
test/
dir and run
npx sst test
.
r
Hi Daniela. Are you familiar with unit testing in general? It’s no different with lambda. We use Jest and apply unit tests to each layer of the app, mocking any external calls made in the unit under test. This is an example of testing the lambda handler entry point