Skip to content

Instantly share code, notes, and snippets.

@ptrthomas
Last active August 3, 2022 13:28
Show Gist options
  • Save ptrthomas/2a1e30bcb4d782279019b3d5c10b3ed1 to your computer and use it in GitHub Desktop.
Save ptrthomas/2a1e30bcb4d782279019b3d5c10b3ed1 to your computer and use it in GitHub Desktop.

refer to this for a working example: schema-like.feature

* def actual = [{ a: 1, b: 'x' }, { a: 2, b: 'y' }]

* def schema = { a: '#number', b: '#string' }
* def partSchema = { a: '#number' }
* def badSchema = { c: '#boolean' }
* def mixSchema = { a: '#number', c: '#boolean' }

* def shuffled = [{ a: 2, b: 'y' }, { b: 'x', a: 1 }]
* def first = { a: 1, b: 'x' }
* def part = { a: 1 }
* def mix = { b: 'y', c: true }
* def other = [{ a: 3, b: 'u' }, { a: 4, b: 'v' }]
* def some = [{ a: 1, b: 'x' }, { a: 5, b: 'w' }]
Normal Form In-Line Form
* match actual[0] == schema * match actual[0] == '#(schema)'
* match actual[0] contains partSchema * match actual[0] == '#(^partSchema)'
* match actual[0] contains any mixSchema * match actual[0] == '#(^*mixSchema)'
* match actual[0] !contains badSchema * match actual[0] == '#(!^badSchema)'
* match each actual == schema * match actual == '#[] schema'
* match each actual contains partSchema * match actual == '#[] ^partSchema'
* match each actual contains any mixSchema * match actual == '#[] ^*mixSchema'
* match each actual !contains badSchema * match actual == '#[] !^badSchema'
* match actual contains only shuffled * match actual == '#(^^shuffled)'
* match actual contains first * match actual == '#(^first)'
* match actual contains any some * match actual == '#(^*some)'
* match actual !contains other * match actual == '#(!^other)'
* match actual contains deep part * match actual == '#(!+part)'
* match actual contains '#(^part)' # NA
* match actual contains '#(^*mix)' # NA
* assert foo.length == 2 * match foo == '#[2]'
@beingautomation007
Copy link

How can i assert when i am expecting that the value of key should match any of the 2 values. how can i impose OR operation over here. Kindly help.
Ex: $..test can have any of the two values i.e. null and #regex ^[ A-Za-z0-9-]*$

@ptrthomas
Copy link
Author

hey @BeingAutomation please use StackOverflow for questions: https://stackoverflow.com/questions/tagged/karate - and actually if you do a search you are bound to find solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment