Spying on JQuery Selectors in Jasmine

前端 未结 6 1457
执念已碎
执念已碎 2020-12-02 15:29

I am unit testing some JavaScript with Jasmine and wish to spy on (mock) an element of the DOM that is accessed by a jQuery selector.

My spec is:

it(         


        
6条回答
  •  忘掉有多难
    2020-12-02 15:42

    You could create your own fake DOM element and then use $('#elementid')[0] as usual

    addFakeElementWithId = function (elementId) {
          var fake = document.createElement("div");
          fake.setAttribute("id", elementId);
          document.body.appendChild(fake);
       };
    

提交回复
热议问题