Karate not contains any

24 Views Asked by At

I'm trying to assert that an array does not contain any of given elements. What i've tried so far:

* def foo = [1, 2, 3]
* match foo !contains [3, 4] # renders true, but i need it to be false --> !contains is not for this kind of assert
* match each foo !contains [3, 4] # error: datatypes don't match
* match foo !contains each [3, 4] # error: js syntax error
* match foo !contains any [3, 4] # error: !contains any not available

Is there a way to achive this kind of assert in Karate?

1

There are 1 best solutions below

0
Peter Thomas On BEST ANSWER

Yes, I myself get confused with !contains and don't recommend it.

I suggest you do a two-step filter. Use this as a reference:

* def bad = [1, 2, 3]
* def actual = [4, 5, 6]
* def temp = actual.filter(x => bad.includes(x))
* match temp == []

Also refer this answer for more tips: https://stackoverflow.com/a/62567262/143475