Using window object and jQuery while testing in terminal with node

233 views
Skip to first unread message

Roman Snitko

unread,
Mar 8, 2013, 4:05:18 AM3/8/13
to jsclas...@googlegroups.com
I was trying to set up the environment properly so that my tests run with

node test/runner.js

 Unfortunately, everything ends up with an error when jQuery couldn't find a window object. I tried different approaches, one of which was using jsdom:

var jsdom = require("jsdom").jsdom;
JS.ENV.window = jsdom().createWindow()
JS.ENV.document = JS.ENV.window.document;

In this case tests passed, however I saw json string as output in the terminal instead of pretty green messages and I suspect this was because I changed the window object.
Then I saw there's a "js.class/source/dom" directory with some files relatd to DOM, but I'm not sure how all this is supposed to work, there's nothing about it in documentation.

I also saw the stubbing technique used in test's examples in documentation, but that's not gonna help me in my case, because I'm not making any ajax-requests and I really need jQuery functionality.

Surely, there must be a way to run JS.Test specs and use jQuery?

James Coglan

unread,
Mar 17, 2013, 4:56:22 PM3/17/13
to jsclas...@googlegroups.com
On 8 March 2013 09:05, Roman Snitko <roman....@gmail.com> wrote:
I was trying to set up the environment properly so that my tests run with

node test/runner.js

 Unfortunately, everything ends up with an error when jQuery couldn't find a window object. I tried different approaches, one of which was using jsdom:

var jsdom = require("jsdom").jsdom;
JS.ENV.window = jsdom().createWindow()
JS.ENV.document = JS.ENV.window.document;

I'm not sure what you're trying to do without being able to see your code, so I'm not sure why you're trying to run jQuery-based code in Node. jQuery is a browser library, I would write browser tests for it if you don't want to stub it out.

Then I saw there's a "js.class/source/dom" directory with some files relatd to DOM, but I'm not sure how all this is supposed to work, there's nothing about it in documentation.

This is a "private" package that's there to support the browser UI for JS.Test. It's very small and not supposed to be a replacement for jQuery.
 
Surely, there must be a way to run JS.Test specs and use jQuery?

As I said, run them in the browser. Running them in Node with fake DOM libraries will lead you to work around bugs in that DOM implementation rather than in real browsers; I've never found a fake DOM library that was worth the time spent working around its bugs. 
Reply all
Reply to author
Forward
0 new messages