Qunit - Typescript Unit Testing How to add content to qunit-fixture in a qunit test case

364 views Asked by At

I am quite new to qUnit and trying to populate qunit-fixture with some content in my test case. However it is not working. Test method is running fine in visual studio, however I am unable to populate content in "qunit-fixture" div.

Looking for help from the community here.

Please refer below code

/// <reference path="../scripts/typings/qunit/qunit.d.ts" />
/// <chutzpah_reference path="../Scripts/jquery-1.10.2.js"/>

test("Test1",() => {

    $("#qunit-fixture").append("test");
    ok(true);
});
1

There are 1 answers

1
jplindgren On

I do not know typescript, but i think you have a wrong jquery selector.

qunit-fixture is by default an id of an div element in your html test page. So the code to populate should be some like that.

$("#qunit-fixture").append("test");

I usually put this in my test setup. In pure javascript would be something like that.

module('MyModule',{
    setup: function() {
        $('#qunit-fixture').append("<button id='myButton'>Test button</button>");
       //other stuff
    },
    teardown: function() {
        // clean up after each test
    }
});

I hope this helps to solve your problem.