I am just getting started with JS Unit Testing and am trying out qUnit.
When my JS executes (via it's init() function) it grabs some nodes from the page which are required for the JS to run properly.
Currently my qUnit test is failing before it even starts because it doesn't find those nodes in the test html file.
I'm not using jQuery in my JS at all (no framework).
I've done some looking around that implies I should load an iframe with my page onto the test.html page. I would then need to replace document with iframe.document or something similar, right?
Is that possible? How would I do that so my document.getElementById() doesn't fail. It sounds like I need to set the context of the local test.html the same as the context of the iframe (window, document etc wise, at least, so it can reference the same nodes).
Any thoughts?
Yes as far as I know, the document nodes you mention are test data. The QUnit unit-test.html
page contains a <div id='qunit-fixture'
which is where your your test data stuff should be.
So far I've had a good time with QUnit testing pure JS that is completely decoupled from the UI, the unit tests help with the separation too.
However, for something more UI related you might want to take a look at how JQuery UI uses QUnit. See the accordion widget unit tests