Last active
October 19, 2021 21:41
-
-
Save ptrthomas/a44579df0806ccd42494781b3832f9d0 to your computer and use it in GitHub Desktop.
Karate and JSON `contains`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given def cat = | |
""" | |
{ | |
name: 'Billie', | |
kittens: [ | |
{ id: 23, name: 'Bob' }, | |
{ id: 42, name: 'Wild' } | |
] | |
} | |
""" | |
# normal 'equality' match. the wildcard '*' in the json-path returns an array | |
Then match cat.kittens[*].id == [23, 42] | |
# 'contains' just checks if the expected items exist | |
Then match cat.kittens[*].id contains [42, 23] | |
# and yes, you can assert against nested objects within JSON arrays ! | |
Then match cat.kittens contains [{ id: 42, name: 'Wild' }, { id: 23, name: 'Bob' }] | |
# ... and even ignore fields at the same time ! | |
Then match cat.kittens contains { id: 42, name: '#string' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment