I am trying out qunit while writing a jQuery plugin and I was wondering how I can test the following:
(function($){
$.fn.myPlugin = function(options){
var defaults = {
foo: function(){
return 'bar';
}
};
options = $.extend(defaults, options);
return this.each(function(){ ... });
};
})(jQuery);
This is a simple version of my qunit test:
module('MyPlugin: Configuration');
test('Can overwrite foo', function(){
var mockFoo = function(){
return 'no bar';
};
//equals(notsure.myPlugin({ foo: mockFoo }, 'no bar', 'Overwriting failed');
});
So I was wondering how I could expose internal methods/members from my plugin inside my tests?
Nice after I made my bounty I found a really good site that explains how to use .data() to expose plubic properties and methods.
Here you can find the whole blog post: building object oriented jquery plugin.
This is whole example from the above link so all credits go to the author of the blog post.