3

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?

Nikolay Melnikov
  • 1,395
  • 1
  • 15
  • 25
  • i appreciate this was asked a while ago now, but quick suggestion: if you were to put a code example here, someone may provide you with a more in-depth answer, with multiple options for your situation – Darren Shewry Nov 19 '15 at 13:18
  • A bit late but still, @adarren - i too facing same challenge as Nikolay Melnikov. My question link is : http://stackoverflow.com/questions/37921670/is-it-possible-to-mock-local-variable-in-angularjs-factory-from-karma. Any help would be much appreciated. I know this question has already an accepted answer. But still i am looking for some great answer as it is more than 1 year ahead now :) – Mithun Shreevatsa Jun 22 '16 at 16:59

1 Answers1

3

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.

Boris Charpentier
  • 3,515
  • 25
  • 28