In your unit tests, you shouldn't be concerned about testing every implementation detail. You don't really care about that anonymous function, but rather that the side effects or return value of your SUT matches expectations. You should test that $scope.arr contains the expected data after calling your function.
If you really needed to get access to that function, you'd have to use something like a spy to record when _.forEach is called, then access that argument:
var forEachSpy = sinon.spy(_, 'forEach');
var forEachFn = forEachSpy.lastCall.args;
But again, I would argue that testing in this manner does not add value and only leads to brittle tests that do not remain useful upon refactoring of implementation details. For example, say you use a regular Array forEach in the future; your test would break, but you don't really care how you loop through the structure, only that your scope is correct.
Asked in February 2016Viewed 3,260 timesVoted 4Answered 1 times