Did i invoke the objects wrong, there are 2 null keys in one map using Karate API

Viewed 48
  • def array = [Red,Green,Yellow,null]

  • def map = {'Red': 0, 'Green': 0, 'Yellow': 0 , 'Grey': 0, null : 0}

  • karate.forEach(array, function(x){ map.put(x,map.get(x) + 1) })

  • print map

Output : { "Red": 1, "Green": 1, "Yellow": 1, "Grey": 0, "null": 0, "null": 1.0 }

1 Answers

I really don't know why the 2 nulls show up. Feel free to debug and let us know, this is never a concern in normal use, you should never have null keys anyway when all the code behind expects strings. Make this one change please:

* karate.forEach(array, function(x){ if (x) map[x] = map.get(x) + 1 })
Related