Qunit qunit-fixture div gets deleted running unit

2019-07-06 16:42发布

I have an issue that when I try to append or set up HTML code in the div id="qunit-fixture" when testing with Qunit running under ReSharper 8. The div id="qunit-fixture" is deleted for some reason. I need to test events specified in the document ready function but can not do so if I can not add the elements in the div id="qunit-fixture". Are there any solutions for this?

1条回答
再贱就再见
2楼-- · 2019-07-06 17:21

It does not get deleted. It is simply not there with the Resharper QUnit test runner!

You can see for yourself when the browser opens, and check the "view source" of the HTML.

To overcome this problem, you might want to setup your QUnit test module as follows:

module("Tests for DOM manipulation", {
    setup: function() {
        $("body").append("<div id='qunit-fixture' />");
    },
    teardown: function () {
        $("#qunit-fixture").remove();
    }
});

test("Some atomic jQuery test", function () {
    $("#qunit-fixture").append("<span id='myId' />");

    ...
 }
查看更多
登录 后发表回答