Add unit tests for CDK L3 construct in this repository.
When creating unit tests using fine-grained assertions, follow these principles:
- Verify security configurations and business requirements.
- Test boundary conditions and error cases in construct properties.
- Verify that required resources are created and properly linked.
- Verify that required resources contain the right IAM permissions.
- Focus unit tests on specific behaviors that must not change.
- if applicable, mock CDK assets like docker images or lambda function to prevent generating zip files during test execution. This speeds up test execution.
- each test should only test a single specific aspect of the construct.
- Ensure that the unit test cover constructs and not stacks.
The unit test should conform to the following guidelines:
- use jest as the test framework
- add comments to explain what every test is covering
- use a meaningful name of the test
- do not add extra
describeblocks. - use the
test()method to run an individual test - do not import
describe,test,jestorexpect. - use the
aws-cdk-lib.assertionslibrary from CDK v2 for assertions - use single named imports
- use arrow functions for all test functions.
- the test file must be named like the source ending with
.test.ts. Example: if the source file is namedapi-construct.ts, the test file must be namedapi-construct.test.ts
Install Prompt
Add this prompt to your Amazon Q CLI prompt library:
1. Download to local prompt library:
mkdir -p .amazonq/cli-prompts && curl -o .amazonq/cli-prompts/cdk-unit-tests-for-typescript-and-jest.md https://promptz.dev/prompts/testing/cdk-unit-tests-for-typescript-and-jest/index.md2. Use with Q CLI:
q prompts use cdk-unit-tests-for-typescript-and-jest