AngularJS + Jasmine Unit Test: How to make an angular.constant visible inside the angular.forEach()?
<p>How to make an angular.constant visible inside the angular.forEach()?</p>

<p>In the below sample, angular.constant is accessible in the parent and child describe blocks. I was trying to optimize the code, by using hash and looping through to run the tests, so started using angularjs.forEach(). But, it appears that, the angular.constant is not visible inside the angular.forEach(). Any idea why constant is not accessible (while service is) inside angular.forEach()? </p>

<pre><code>describe("utilsService:", function(){

    beforeEach(module('utilsService'));

    var KiB;
    var GiB;
    beforeEach(inject(function(_KiB_){
          KiB = _KiB_;
    }));
    beforeEach(inject(function(_GiB_){
          GiB = _GiB_;
    }));

    var utilsService;
    beforeEach(inject(function(_utilsService_){
          utilsService = _utilsService_;
    }));


    describe('Constant values', function() {

/* The below test works fine */
        it("KiB constant in describe", function(){
            console.log("KiB value is " + KiB);
            expect(KiB).toEqual(1024);
        });

        tests = {
          'KiB value': {
            'INPUTS': {
              'CONSTANT': KiB
            },
            'EXPECTED': {
              'VALUE': 1024
            }
          },
          'GiB value': {
            'INPUTS': {
              'CONSTANT': GiB
            },
            'EXPECTED': {
              'VALUE': 1024 * 1024
            }
          }
        }

        angular.forEach(tests, function(t_hash, t_name){

          var val = t_hash.INPUTS.CONSTANT;
          var exp_val = t_hash.EXPECTED.VALUE;

/* The below test is failing */
          it(t_name, function(){
              console.log("TC: " + test_api_name + " " + t_name );
              expect(val).toEqual(exp_val);
          })
        });

    });
</code></pre>

<p>Note: Call to Service functions (like below compareSize()) is working just fine.</p>

<pre><code>describe('compareSize()', function() {
    test_api_name = 'compareSize()';
    tests = {
      'size1 is greater than size2': {
        'INPUTS': {
          'SIZE1_UNIT': '2 TB',
          'SIZE2_UNIT': '2048 KB'
        },
        'EXPECTED': {
          'RETURN': 1
        }
      },

      'float size1 is greater than int size2': {
        'INPUTS': {
          'SIZE1_UNIT': '1.50 TB',
          'SIZE2_UNIT': '1 TB'
        },
        'EXPECTED': {
          'RETURN': 1
        }
      }
    }

    angular.forEach(tests, function(t_hash, t_name){
      var size1_unit = t_hash.INPUTS.SIZE1_UNIT;
      var size2_unit = t_hash.INPUTS.SIZE2_UNIT;
      var exp_ret = t_hash.EXPECTED.RETURN;

      it(t_name, function(){
          console.log("TC: " + test_api_name + " " + t_name );
          var ret = utilsService.compareSize(size1_unit, size2_unit);
          expect(ret).toEqual(exp_ret);
      })
    });
</code></pre>