aws-cdk-lib.assertions.Matcher

class Matcher

LanguageType name
.NETAmazon.CDK.Assertions.Matcher
Gogithub.com/aws/aws-cdk-go/awscdk/v2/assertions#Matcher
Javasoftware.amazon.awscdk.assertions.Matcher
Pythonaws_cdk.assertions.Matcher
TypeScript (source)aws-cdk-lib » assertions » Matcher

Implemented by Capture

Obtainable from Match.absent(), Match.anyValue(), Match.arrayEquals(), Match.arrayWith(), Match.exact(), Match.not(), Match.objectEquals(), Match.objectLike(), Match.serializedJson(), Match.stringLikeRegexp()

Represents a matcher that can perform special data matching capabilities between a given pattern and a target.

Example

// Given a template -
// {
//   "Resources": {
//     "MyBar": {
//       "Type": "Foo::Bar",
//       "Properties": {
//         "Fred": ["Flob", "Cat"]
//       }
//     }
//   }
// }

// The following will NOT throw an assertion error
template.hasResourceProperties('Foo::Bar', {
  Fred: Match.arrayWith(['Flob']),
});

// The following will throw an assertion error
template.hasResourceProperties('Foo::Bar', Match.objectLike({
  Fred: Match.arrayWith(['Wobble']),
}));

Initializer

new Matcher()

Properties

NameTypeDescription
namestringA 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

NameDescription
test(actual)Test whether a target matches the provided pattern.
static isMatcher(x)Check whether the provided object is a subtype of the IMatcher.

test(actual)

public test(actual: any): MatchResult

Parameters

  • actual any — the target to match.

Returns

  • MatchResult

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.


static isMatcher(x)

public static isMatcher(x: any): boolean

Parameters

  • x any

Returns

  • boolean

Check whether the provided object is a subtype of the IMatcher.