Can't read context in aws cdk construct when unit testing
See original GitHub issue❓ General Issue
Can’t read context in aws cdk construct when unit testing Here is the type script code in cdk constuct:
const ENV_NAME = this.node.tryGetContext("ENV_NAME") ?
this.node.tryGetContext("ENV_NAME") : ``;
if (_.isEmpty(ENV_NAME)) {
throw new Error('ENV_NAME context is required...')
}
Following is the error when unit testing from my jest unit test after run…
FAIL test/cdk.predeploy.test.ts ✕ Empty Stack (5ms)
● Empty Stack
ENV_NAME context is required...
Need help! Thanks.
The Question
Environment
- CDK CLI Version:
- Module Version:
- OS:
- Language:
Other information
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Testing constructs - AWS Cloud Development Kit (AWS CDK) v2
The standard approach to testing AWS CDK apps uses the AWS CDK's assertions module and popular test frameworks like Jest for TypeScript and...
Read more >Get a value from a context variable - AWS Documentation
To create a command line context variable, use the --context (-c) option, as shown in the following example. cdk synth -c bucket_name=mygroovybucket. To...
Read more >Testing constructs - AWS Cloud Development Kit (AWS CDK) v1
This article illustrates the standard approach to testing AWS CDK apps using the AWS CDK's assertions module and popular test frameworks such as...
Read more >Runtime context - AWS Cloud Development Kit (AWS CDK) v2
Context values that are set by the AWS CDK Toolkit (the cdk command) can be set automatically, from a file, or from the...
Read more >Best practices for developing and deploying cloud ...
With the AWS CDK, developers or administrators can define their cloud infrastructure ... To consistently run a full suite of unit tests at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I hope to load context of
cdk.json
whennpm test
run!I never figured out how to do this with some of my nested context values, but I did get my testing to work in Python when I refactored like this. May not be the best option for you, but it works.
And the mocking…