私はモックアウトしたい既存のプラグインを使用するプラグインを作成しています。私が書いているプラグインは、次のようにソートの見え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;
}
実際のプラグインのインスタンスはまだ呼び出されています。