Testing javascript inside IIFE

纵然是瞬间 提交于 2020-01-13 07:24:50

问题


My team leader wants me to wrap my js code inside an IIFE immediatly-invoked function expression. I can't figure out how to spyOn in my jasmine spec file.

How would I spyOn the follow:

(function(){
function_1(){...}
function_2(){...}
});

spyOn(window,'function_1') doesn't work. Passing window into the IIFE doesn't work.

Trying both (x=function()... and (function x() ... then spyOn(x,'function_1') doesn't work either.

I couldn't find anything on-line about this.


回答1:


@user29998, if you can expose those functions to test via a return block, you can do something as found on this jsbin link: http://jsbin.com/yohux/1/edit?js,console



来源:https://stackoverflow.com/questions/24066796/testing-javascript-inside-iife

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!