Search code examples
javascriptunit-testingcross-browserjs-test-driver

JsTestDriver easy appending of elements to the body via :DOC syntax?


I'm using js-test-driver to test my Javascript code on several browsers:

TestCase("DropDownValueReplacerTestCase", {
    setUp:function() {
        console.log("BEGIN: setUp");
        /*:DOC += <form id="bob"></form> */

        console.log("END: setUp");
    },

    tearDown:function() {
        console.log("BEGIN: tearDown");

        console.log("END: tearDown");
    },

    testA:function() {
        console.log("Creating foo element.");

        /*:DOC += <form id="bob"></form> */

        var forms = document.getElementsByTagName('form');

        assertNotNull(forms);
        console.log("forms:" + forms.length);
        assertTrue(forms.length > 0);

        var bob = document.getElementById("bob");
        assertNotNull(bob); 
    }
});

The /*:DOC += */ statement is supposed to append html to the body tag, but apparently it doesn't work for some reason.

When I replace the :DOC syntax with something more verbose, such as:

    var form = document.createElement("form");
    document.body.appendChild(form);
    form.id = "bob";

the test works just fine.

Did they change something and not update the documentation? I checked the hello world example out of the trunk on SVN per the website's directions to test this out. There doesn't seem to be a version number or anything.


Solution

  • It works on mine, are you using version 1.2, here?

    I know they did not support it in earlier versions and maybe trunk is unstable (even though it does not look like its been modified for a while)