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

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

angularjs - How do I mock local variable for a function in a service? Jasmine/Karma tests

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...