Given: client-side javascript code (runs in browser, uses jquery etc). Currently the code is tested with Rhino and envjs. We would like to switch to node.js. However, after some research, couldn’t find any envjs-like supplementary that emulates a browser.
While running node.js “as is”, even basic capabilities like alert() or window are missing.
Is there any standard bundle, similar to Rhino & envjs for node.js please?
You could use zombie.js, which has everything you need for testing. Or you could leverage jsdom (which zombie.js uses internally) to get a DOM in node.js, and execute your tests against that DOM.
I can also recommend testling, which executes tests according to your specification in all common browsers — the code is running in actual browsers against your service.
Here’s a simple example with jsdom:
Instead of
urlabove, you could have an HTML document, or fragment.You can also load a page and fetch any external resources, instead of providing jQuery etc directly to jsdom:
Again, zombie.js uses jsdom internally and it might be a better starting point.