Skip to content

(assertions): absentProperty() and not() matchers are incompatible with hasResourceProperties #16626

Closed
@nija-at

Description

Given a template that has a resource with no Properties (just Type)

{
  "Resources": {
    "IamUser1": {
      "Type": "AWS::IAM::User"
    }
  }
}

The following assertion should pass but throws the error Template has 1 resources with type AWS::IAM::User, but none match as expected.

Template.fromStack(stack).hasResourceProperties('AWS::IAM::User', {
  UserName: Match.absentProperty(),
});

Similarly, the assertion -

Template.fromStack(stack).hasResourceProperties('AWS::IAM::User', Match.not({
  UserName: 'MyUser',
}));

The workaround is to do -

Templte.fromStack(stack).hasResource('AWS::IAM::User', {
  Properties: Match.absentProperty(),
});

This is 🐛 Bug Report

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/assertionsRelated to the @aws-cdk/assertv2 packagebugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions