Repository: angular/angular.js
File: test/ng/rootScopeSpec.js (JavaScript)

Code before:
      deregisterOne();
      deregisterNone();
      scope.a = 'xxx';
      scope.b = 'yyy';
      scope.$digest();
      expect(log).toEqual('');
    });

    it('should remove all watchers once one-time/constant bindings are stable', function() {
      //empty
      scope.$watchGroup([], noop);
      //single one-time
      scope.$watchGroup(['::a'], noop);
      //multi one-time
      scope.$watchGroup(['::a', '::b'], noop);
      //single constant
      scope.$watchGroup(['1'], noop);
      //multi constant
      scope.$watchGroup(['1', '2'], noop);

      expect(scope.$$watchersCount).not.toBe(0);
      scope.$apply('a = b = 1');
      expect(scope.$$watchersCount).toBe(0);
    });

    it('should maintain correct new/old values with one time bindings', inject(function($rootScope, $exceptionHandler) {
      var newValues;
      var oldValues;
      $rootScope.$watchGroup(['a', '::b', 'b', '4'], function(n, o) {
        newValues = n.slice();
        oldValues = o.slice();
      });

      $rootScope.$apply();
      expect(newValues).toEqual(oldValues);
      expect(oldValues).toEqual([undefined, undefined, undefined, 4]);

      $rootScope.$apply('a = 1');
      expect(newValues).toEqual([1, undefined, undefined, 4]);
      expect(oldValues).toEqual([undefined, undefined, undefined, 4]);

      $rootScope.$apply('b = 2');
      expect(newValues).toEqual([1, 2, 2, 4]);
      expect(oldValues).toEqual([1, undefined, undefined, 4]);

      $rootScope.$apply('b = 3');
      expect(newValues).toEqual([1, 2, 3, 4]);
      expect(oldValues).toEqual([1, 2, 2, 4]);

      $rootScope.$apply('b = 4');
      expect(newValues).toEqual([1, 2, 4, 4]);

Review comment (suggestion):
`$exceptionHandler` is not used. And you could probably use `scope` instead of `$rootScope` to avoid `inject()` altogether.

Code after:
      deregisterOne();
      deregisterNone();
      scope.a = 'xxx';
      scope.b = 'yyy';
      scope.$digest();
      expect(log).toEqual('');
    });

    it('should remove all watchers once one-time/constant bindings are stable', function() {
      //empty
      scope.$watchGroup([], noop);
      //single one-time
      scope.$watchGroup(['::a'], noop);
      //multi one-time
      scope.$watchGroup(['::a', '::b'], noop);
      //single constant
      scope.$watchGroup(['1'], noop);
      //multi constant
      scope.$watchGroup(['1', '2'], noop);

      expect(scope.$$watchersCount).not.toBe(0);
      scope.$apply('a = b = 1');
      expect(scope.$$watchersCount).toBe(0);
    });

    it('should maintain correct new/old values with one time bindings', function() {
      var newValues;
      var oldValues;
      scope.$watchGroup(['a', '::b', 'b', '4'], function(n, o) {
        newValues = n.slice();
        oldValues = o.slice();
      });

      scope.$apply();
      expect(newValues).toEqual(oldValues);
      expect(oldValues).toEqual([undefined, undefined, undefined, 4]);

      scope.$apply('a = 1');
      expect(newValues).toEqual([1, undefined, undefined, 4]);
      expect(oldValues).toEqual([undefined, undefined, undefined, 4]);

      scope.$apply('b = 2');
      expect(newValues).toEqual([1, 2, 2, 4]);
      expect(oldValues).toEqual([1, undefined, undefined, 4]);

      scope.$apply('b = 3');
      expect(newValues).toEqual([1, 2, 3, 4]);
      expect(oldValues).toEqual([1, 2, 2, 4]);

      scope.$apply('b = 4');
      expect(newValues).toEqual([1, 2, 4, 4]);