我想围绕依赖于jQuery.panzoom的指令编写一些单元测试
例如,我在指令中初始化插件,如下所示:
...
function init(options) {
element.panzoom(options);
panZoom = element.panzoom("instance");
}
...但是,当我运行测试时,panZoom是未定义的。我不确定如何在我的测试中设置jQuery.panzoom。我无法导入它,因为它不是一个模块。
任何指导都是很棒的。
干杯。
发布于 2014-07-25 22:48:47
在测试本身中,我用我关心的函数模拟了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();
...
}));https://stackoverflow.com/questions/24955950
复制相似问题