At my job we use a platform written in Java with business logic mostly written in JavaScript and executed by Nashorn (I think it could be Rhino or GraalVM as well). This decision was justified by the ability to dynamically update business domain metadata and GUI forms on client.
This JS code is located both in separate .js files and inside tags in .xml files. XML files contain GUI form descriptions for the custom Swing GUI engine, and JS in XML tags is used for the form elements handlers.
The problem is none of this JS code has automated tests.
I'm not experienced in automated testing, I used only JUnit a couple of times, and I don't understand if it's possible to test such JS code at all.
Have anyone of you ever written automated tests for the code which is executed from some other code? Is it possible (especially as a Maven task), and if it is - how one can do it?
I've searched for examples but couldn't find anything to point the direction.
Also: is it possible to debug such code some other way than console.log() and searching/grepping in logs?
I understand that it is another question but for me both of them are parts of the same problem because without tests every change that involves some data manipulation ends with the initial code covered with console.log() which I then remove before commit.