1

I'm looking for a simple technique to match objects where the key may not be known in advance (e.g. we may fetch the schema as part of the test). As a contrived example:

    Scenario:
        * def result = { foo: 'bar' }
        * def key = 'foo'

        Then match result == { '#(key)': 'bar' }

...which doesn't currently work.

Tim Keating
  • 6,443
  • 4
  • 47
  • 53

1 Answers1

4

Once you realize there is a JavaScript engine behind the scenes, you will get even more ideas :)

* def result = { foo: 'bar' }
* def key = 'foo'
* def expected = {}
* expected[key] = 'bar'
Then match result == expected

Also do a search for other answers [karate] dynamic you will find many interesting examples such as this one: https://stackoverflow.com/a/57226061/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248