Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

An Angular service has several functions. All of them make use of a local variable defined via a var varName at the top of the file.

Is there any way of mocking this variable when unit-testing the function?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

In short no.

The simplest way would be to put it on $scope level. Or Maybe as an angularjs constant

angular constant

Or if you'r a really crazy dude you can make a script that change the value of the var, but seriously don't do that, it's crazy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...