Santosh Hegde
Santosh Hegde

Reputation: 3520

How to test array of objects matches a pattern in Karate

I have an array of objects like below.

"possibleValues": [
            {
                "unitGroup": "A",
                "measurementUnitResource": [
                    {
                        "unit": "1"
                    },
                    {
                        "unit": "2"
                    },
                    {
                        "unit": "3"
                    }
                 ],
                "unitGroup": "B",
                "measurementUnitResource": [
                    {
                        "unit": "7"
                    },
                    {
                        "unit": "8"
                    },
                    {
                        "unit": "9"
                    }
                 ]
            }
     ]

How to check possibleValues array contains objects of pattern {unitGroup:"#String" measurementUnitResource:[{unit:"#String"}]} in karate.

Upvotes: 2

Views: 1360

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Please read the docs: https://github.com/intuit/karate#schema-validation

* def unitResource = { unit: '#string' }
* match each response.possibleValues contains { unitGroup: '#string', measurementUnitResource: '#[] unitResource' } 

Upvotes: 2

Related Questions