I just started using QUnit, and ran into an issue.
When I write my JavaScript files, I put all of my variables at the top of the page like this:
var $input1 = $('#input1');
var $submit = $('#submit');
Then, I wire up my events like this:
$submit.on('click', function (e) {
submit(e);
});
That works great, and is a good way to not have to keep going through and finding all of the elements every time I need something. (No littering the code with $('#submit')
everywhere.)
However, now that I'm running a test with QUnit, the items in the qunit-fixture
div get replaced every time a new test is run. (I'm rewriting some code that someone else did, so there were some initial existing tests.)
As of right now, the test that the other person wrote appends some static HTML to the qunit-fixture
div in the beforeEach
of the module.
One final note of importance, this is a part of an ASP.NET MVC project, and we're running the tests with chutzpah so we aren't making explicit HTML pages to run each of the test files with. Our intent is to run them in a command line, especially as a part of the build process.
How do I get those static items that should always be on the page to stay that way when we aren't building that full HTML page for them to live in?
EDIT I've done a bit more research into this, and because I'm adding the HTML to the DOM during the Test file, when I select the variable at the top, those elements aren't on the page yet in the file I'm testing.