class Capture
| Language | Type name |
|---|---|
.NET | Amazon.CDK.Assertions.Capture |
Go | github.com/aws/aws-cdk-go/awscdk/v2/assertions#Capture |
Java | software.amazon.awscdk.assertions.Capture |
Python | aws_cdk.assertions.Capture |
TypeScript (source) | aws-cdk-lib » assertions » Capture |
Extends
Matcher
Capture values while matching templates.
Using an instance of this class within a Matcher will capture the matching value.
The as*() APIs on the instance can be used to get the captured value.
Example
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Flob",
// }
// },
// "MyBaz": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Quib",
// }
// }
// }
// }
const fredCapture = new Capture();
template.hasResourceProperties('Foo::Bar', {
Fred: fredCapture,
});
fredCapture.asString(); // returns "Flob"
fredCapture.next(); // returns true
fredCapture.asString(); // returns "Quib"
Initializer
new Capture(pattern?: any)
Parameters
- pattern
any— a nested pattern or Matcher.
Initialize a new capture.
Properties
| Name | Type | Description |
|---|---|---|
| name | string | A name for the matcher. |
name
Type:
string
A name for the matcher.
This is collected as part of the result and may be presented to the user.
Methods
| Name | Description |
|---|---|
| as | Retrieve the captured value as an array. |
| as | Retrieve the captured value as a boolean. |
| as | Retrieve the captured value as a number. |
| as | Retrieve the captured value as a JSON object. |
| as | Retrieve the captured value as a string. |
| next() | When multiple results are captured, move the iterator to the next result. |
| test(actual) | Test whether a target matches the provided pattern. |
asArray()
public asArray(): any[]
Returns
any[]
Retrieve the captured value as an array.
An error is generated if no value is captured or if the value is not an array.
asBoolean()
public asBoolean(): boolean
Returns
boolean
Retrieve the captured value as a boolean.
An error is generated if no value is captured or if the value is not a boolean.
asNumber()
public asNumber(): number
Returns
number
Retrieve the captured value as a number.
An error is generated if no value is captured or if the value is not a number.
asObject()
public asObject(): { [string]: any }
Returns
{ [string]: any }
Retrieve the captured value as a JSON object.
An error is generated if no value is captured or if the value is not an object.
asString()
public asString(): string
Returns
string
Retrieve the captured value as a string.
An error is generated if no value is captured or if the value is not a string.
next()
public next(): boolean
Returns
boolean
When multiple results are captured, move the iterator to the next result.
test(actual)
public test(actual: any): MatchResult
Parameters
- actual
any
Returns
Test whether a target matches the provided pattern.
Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.

.NET
Go
Java
Python
TypeScript (