'stub mock using sinon

I have a Util.js which is as below:

define(function(require) {

    var $ = require('jquery');
    var Util= {};

    Util.DIV_ID = "div[id^='myDiv_']";

    Util.getIndividualFormByDiv = function (index) {
        var divId = $(Util.DIV_ID)[index].id;
        var targetFormTag = 'target=' + '"' + divId + '"';
        return $('[' + targetFormTag + ']');
    };

    return Util;
});

Code using the Util.js:

$(Util.DIV_ID).each(function(index) {
   var $myForm = Util.getIndividualFormByDiv (index);
   // perform operations on form
}

I am now trying to test the above code, for which I need to sinon stub / mock $(Util.DIV_ID) to return an array. How do I do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source