Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(assert): more powerful matchers (aws#8444)
In order to write better assertions on complex resource structs that only test what we're interested in (and not properties that may accidentally change as part of unrelated refactors), add more powerful matchers that can express things like: - `objectLike()` - `arrayWith()` - `stringContaining()` (not implemented by default but easy to add now) We can now write: ```ts expect(stack).toHaveResourceLike('AWS::S3::BucketPolicy', { PolicyDocument: { Statement: arrayWith(objectLike({ Action: arrayWith('s3:GetObject*', 's3:GetBucket*', 's3:List*'), Principal: { AWS: { 'Fn::Sub': stringContaining('-deploy-role-') } } })) } }); ``` And be invariant to things like the order of elements in the arrays, and default role name qualifiers. Refactor the old assertions to be epxressed in terms of the new matchers. NOTE: Matchers are now functions, which won't translate into jsii in the future. It will be easy enough to make them single-method objects in the future when we move this library (or a similar one to jsii). For now, I did not want to let that impact the design. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information