title: How to use CDK fine Grain Assertions Against DefinitionString in AWS::StepFunctions::StateMachine?
body: <p>Following the approach for finely grained assertions, specifically the example against <code>AWS::StepFunctions::StateMachine</code> in
  <a href="https://docs.aws.amazon.com/cdk/v2/guide/testing.html#testing_fine_grained" rel="nofollow noreferrer">https://docs.aws.amazon.com/cdk/v2/guide/testing.html#testing_fine_grained</a>, I can't get the use of <code>Match.serializedJson()</code> to work for my own State Machine definition.</p>
  <p>Here is a snippet of my generated CloudFormation template -</p>
  <pre><code>  &quot;StateMachine985JK630&quot;: {
     &quot;Type&quot;: &quot;AWS::StepFunctions::StateMachine&quot;,
     &quot;Properties&quot;: {
      &quot;RoleArn&quot;: {
       &quot;Fn::GetAtt&quot;: [
        &quot;StateMachineRoleJ4IK852F&quot;,
        &quot;Arn&quot;
       ]
      },
      &quot;DefinitionString&quot;: {
       &quot;Fn::Join&quot;: [
        &quot;&quot;,
        [
         &quot;{\&quot;StartAt\&quot;:\&quot;My Task One\&quot;,\&quot;States\&quot;:{\&quot;My Task One \&quot;:{\&quot;Next\&quot;:\&quot;My Task Two\&quot;,\&quot;Retry\&quot;:[{\&quot;ErrorEquals\&quot;:[\&quot;Lambda.ServiceException\&quot;,\&quot;Lambda.AWSLambdaException\&quot;,\&quot;Lambda.SdkClientException\&quot;],\&quot;IntervalSeconds\&quot;:2,\&quot;MaxAttempts\&quot;:6,\&quot;BackoffRate\&quot;:2}],\&quot;Type\&quot;:\&quot;Task\&quot;,\&quot;ResultPath\&quot;:\&quot;$.truNarrativeAuth\&quot;,\&quot;ResultSelector\&quot;:{\&quot;authString.$\&quot;:\&quot;$.Payload\&quot;},\&quot;Resource\&quot;:\&quot;arn:&quot;,
         {
          &quot;Ref&quot;: &quot;AWS::Partition&quot;
         },
         &quot;:states:::lambda:invoke\&quot;,\&quot;Parameters\&quot;:{\&quot;FunctionName\&quot;:\&quot;&quot;,
         {
          &quot;Fn::GetAtt&quot;: [
           &quot;MyTaskOne&quot;,
           &quot;Arn&quot;
          ]
         },
         &quot;\&quot;,\&quot;Payload.$\&quot;:\&quot;$\&quot;}},\&quot;My Task Two\&quot;:{\&quot;Next\&quot;:\&quot;My Task Three\&quot;,\&quot;Retry\&quot;
         ...
        ]
  ...
  </code></pre>
  <p>The test against <code>DefinitionString</code> in the example in the documents doesn't handle the Arrays or <code>Fn::Join</code> property seen in the above CloudFormation template which is in the rough format of <code>DefinitionString: { 'Fn::Join': [ '', [Array] ] }</code>. My below test works as is, however without checking against properties such as <code>StartAt</code> it's obviously useless.</p>
  <p>My Test -</p>
  <pre><code>// PASSES
  it('should create My Task 1', () =&gt; {
        template.hasResourceProperties('AWS::StepFunctions::StateMachine', {
          DefinitionString: {
            'Fn::Join': [
              '',
              Match.arrayWith([
                // Match.serializedJson(Match.objectLike({ StartAt: 'My Task One' })), // FAILS
                // Match.serializedJson({ StartAt: 'My Task One' }) // FAILS
                // Match.objectLike(Match.serializedJson({ StartAt: 'My Task One' })) // FAILS
                {
                  Ref: 'AWS::Partition',
                },
              ]),
            ],
          },
        });
      });
  </code></pre>
  <p>I have tried</p>
  <ul>
  <li>Lifting the example exactly as it is from the docs (and changing expect properties to my own) but fails with</li>
  </ul>
  <pre><code>Expected JSON as a string but found object at /Properties/DefinitionString
  </code></pre>
  <p>which makes sense given the makeup of DefinitionString.</p>
  <ul>
  <li>Adding any of the commented out lines to the <code>Match.arrayWith([])</code> fail with</li>
  </ul>
  <pre><code>Missing element at pattern index 0 at /Properties/DefinitionString/Fn::Join[1] (using arrayWith matcher)
  </code></pre>
  <p>but I can't quite make sense of this as the functions I am using are 'like' matches.</p>
  <ul>
  <li>Pasting the entire string <code>&quot;{\&quot;StartAt\&quot;:\&quot;My Task One\&quot;...</code> directly as it is into the <code>Match.arrayWith([])</code> which passes but is far from ideal.</li>
  </ul>
  <p>My question is how do I parse the array of strings and objects, then match only what I want? Any guidance would be much appreciated.</p>