karate: Match each not contains / match contains fails unexpectedly for partial objects
There appears to be an issue with the JSON array contains / not contains step, when trying to partially match objects.
Given the following scenario:
Feature: Bug Report
Scenario: Each not contains
* def ar = [{a: 1, b: 2}, {a:3, b:4}]
* match each ar !contains {a:1, b:4}
This fails with: com.intuit.karate.exception.KarateException: path: $[0].a, actual: 1, NOT expected: 1, reason: actual value contains expected
While I would expect this to pass.
Other scenario:
Feature: Bug Report
Scenario: Array contains
* def ar = [{a: 1, b: 2}, {a:3, b:4}]
* match ar contains {a:1}
This fails with: com.intuit.karate.exception.KarateException: path: $[*], actual: [{“a”:1,“b”:2},{“a”:3,“b”:4}], expected: {a=1}, reason: actual value does not contain expected
While I would expect this to pass.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (10 by maintainers)
Commits related to this issue
- fixed edge case in not-contains, ref #501 — committed to karatelabs/karate by ptrthomas 6 years ago
no worries. I tried. cheers.
Thanks for taking the time to reply and the great work you’re doing on this tool. The json responses I’m dealing with are often over 100 lines long, and I usually only need to assert on about 5-10 values scattered throughout the payload in multiple subtrees, and each subtree has 5-10 sibling values which don’t need to be asserted on. Maybe that doesn’t match the use cases of most of your users.
I definitely see the value of adding schema validation for contract coverage, and I use karate fuzzy matching and jsonpath often when asserting on a few values. One of my favorite things about karate is the java interop. If you have a specialized need, it’s easy to extend the functionality. Thanks again.
?
@ericdriggs lol ok thanks, let’s leave it to readers to choose. I really don’t understand what’s going on in the second example, but thanks anyway.
@ptrthomas no problem 😃 Really happy with Karate in general, very little bugs and good documentation. We have a workaround for now.