Testing javascript inside IIFE

2020-08-03 04:12发布

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条回答
欢心
2楼-- · 2020-08-03 04:59

@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

enter image description here

查看更多
登录 后发表回答