Karate: [Feature Request] Ignore order of the objects in the array

Created on 26 Nov 2018  路  3Comments  路  Source: intuit/karate

Consider:

Feature: Un-orderd Array Test Match

Scenario: Test
  * def test =
  """
    {key1: ["1", "2"]}
  """
  * match test == {key1: ["2", "1"]}

Result:
actual: {key1=["1","2"]}, expected: {key1=["2","1"]}, reason: all key-values did not match

It would be amazing if we could match arrays ignoring the order of the items.

question

All 3 comments

@76creates I'm really not sure if you are trolling or not, but have you read the documentation ?

* def test = { key1: ['1', '2']}
* match test.key1 contains only ['2', '1']
* def nums = ['2', '1']
* match test == { key1: '#(^^nums)' }

Wasn't trolling but looks to me like I didn't read/forgot about the part "contains short-cuts", my bad, tried searching for some keywords as well but it seams like I failed totally. Monday begins, rated R. Also example was bad, wanted to present something like {key1': ["1", "2"], key2: "3"}. Thanks.

@76creates hey no worries ^_^ feel free to ask for help on this thread or better still on Stack Overflow: https://stackoverflow.com/questions/tagged/karate

normally contains should work. the short-cuts are if you insist on doing a full json match in one-line, but the second line above should be sufficient

Was this page helpful?
0 / 5 - 0 ratings