Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

karate-config.js : Not able to add new {key : value} pair to Map generated from Java API #1469

Closed
workwithprashant opened this issue Feb 3, 2021 · 2 comments

Comments

@workwithprashant
Copy link

Notes:

  • Download Sample project and execute mvn clean test
  • Please build develop branch of Karate locally with version 2.0.0
  • Similar example used to work with 0.9.6 version of Karate

I am using JavaDemo class from https://github.com/intuit/karate#calling-java in karate-config.js as below. configMap is not getting updated with new element project

  var configMap = jd.doWork("fromJS");
  karate.log("configMap BEFORE adding project = ", configMap)
  configMap['project'] = {name: "DEMO PROJECT"}
  karate.log("configMap AFTER adding project = ", configMap)
Console Output:
11:04:46.203 [main] INFO  com.intuit.karate - configMap BEFORE adding project =  {
  "someKey": {
  }
}
11:04:46.203 [main] INFO  com.intuit.karate - configMap AFTER adding project =  {
  "someKey": {
  }
}

Following code works if I don't use jd.doWork("fromJS") and adds new element project

  var configMap = {"test" : "initial"};
  karate.log("configMap BEFORE adding project = ", configMap)
  configMap['project'] = {name: "DEMO PROJECT"}
  karate.log("configMap AFTER adding project = ", configMap)
Console Output:
11:07:21.984 [main] INFO  com.intuit.karate - configMap BEFORE adding project =  {
  "test": "initial"
}
11:07:22.003 [main] INFO  com.intuit.karate - configMap AFTER adding project =  {
  "test": "initial",
  "project": {
    "name": "DEMO PROJECT"
  }
}
@ptrthomas
Copy link
Member

cc @joelpramos interesting one

since the JS engine changed, unless we "patch" the objects originating from Java they won't "behave" like JS

so this is the fix: var configMapFailure = karate.toJson(jd.doWork("fromJS"));

I will document this in the release notes

@joelpramos
Copy link
Contributor

That explains a few things

I also noticed that we used to have several for-each pieces of Javascript code to map info into a DTO and doesn't work anymore - moving to use karate.map() works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants