Я пишу плагин, который использует существующий плагин, который я хотел бы издеваться.Как мне высмеять плагин jQuery?
плагин Я пишу выглядит вроде этого:
(function($){
$.widget("myPlugin",{
_create: function(){
var otherControl = $("<div></div>");
otherControl.pluginWhichShouldBeMocked({foo: "bar"});
this.element.append(otherControl);
}
});
})(jQuery);
И у меня есть тест жасмин, какой вид выглядит следующим образом:
describe("When creating", function(){
var element;
var passedOptions;
beforeEach(function(){
jQuery.pluginWhichShouldBeMocked = function(options){
passedOptions = options;
}
element = $("<div></div>");
element.myPlugin();
});
it("should create the other plugin and pass 'bar' to it as the foo parameter", function(){
expect(passedOptions.foo).toEqual("bar");
});
});
Эта линия, где я пытался чтобы высмеять плагин:
jQuery.pluginWhichShouldBeMocked = function(options){
passedOptions = options;
}
Фактический экземпляр плагина все еще называется.