Can anyone advice on how should I go about testing...
# help
a
Can anyone advice on how should I go about testing my APIs using jest?
r
Are you already familiar with Jest?
a
I have used it before a couple of times with sst stacks so yep, I am.
r
I ask because it's no different to testing anything else. Are you aiming to do unit or integration testing?
a
unit tests primarily.
r
Then it's all about mocking external dependencies
a
okay, but where should I be creating my tests, sst had a tests directory, should I be writing my tests in them?
the confusion is that how would I test the API when my lambdas are expecting events and contexts?
r
I'd say that's for testing your infrastructure is deployed properly, it sounds like you want to test the code that will be run by that infrastructure. I therefore have a separate test folder inside my src folder for our tests
Structure inside that mirrors the code's folder structure
a
Yes, I want to test my code, okay, that makes sense. Where do you trigger the tests via CI?
r
I have an npm script that is run before deployment
a
so basically itโ€™s something like
deploy: yarn test && yarn sst deploy
, is that the case?
r
Yes, or call it via a separate hook predeploy. E.g. In seed there are a couple of hooks you can use predeploy to run scripts
a
okay, thank you, as always, you were quick. I really appreciate the guidance. ๐Ÿ™
r
No worries ๐Ÿ˜Š