我想在我的指令中编写一些依赖于jQuery.panzoom
的单元测试例如,我在我的指令中初始化插件,如下所示:
...
function init(options) {
element.panzoom(options);
panZoom = element.panzoom("instance");
}
...
但是,当我运行测试时,panZoom未定义。我不确定如何在我的测试中设置jQuery.panzoom。我无法导入它,因为它不是模块。
任何指导都会很棒。
干杯。
答案 0 :(得分:0)
在测试中,我用我关心的函数嘲笑了jQuery.panzoon:
beforeEach(inject(function (_$rootScope_, _$compile_) {
scope = _$rootScope_;
compile = _$compile_;
mockPanZoom = {
matrix : [],
reset : function(value) {},
setMatrix : function(m) {
this.matrix = m;
},
getMatrix : function() {
return this.matrix;
}
}
jQuery.fn.panzoom = function() {
return mockPanZoom;
};
spyOn(jQuery.fn, 'panzoom').andCallThrough();
...
}));