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

Code before:
                'ng-model-options="{ debounce: 30000 }"' +
              '/>');

          browserTrigger(inputElm[0], 'click');
          expect($rootScope.color).toBe('white');
          browserTrigger(inputElm[1], 'click');
          expect($rootScope.color).toBe('white');
          $timeout.flush(12000);
          expect($rootScope.color).toBe('white');
          $timeout.flush(10000);
          expect($rootScope.color).toBe('red');

        });


        it('should not trigger digest while debouncing', inject(function($browser) {
          var inputElm = helper.compileInput(
              '<input type="text" ng-model="name" name="alias" ' +
                'ng-model-options="{ debounce: 10000 }"' +
              '/>');

          var watchSpy = jasmine.createSpy('watchSpy');
          $rootScope.$watch(watchSpy);

          helper.changeInputValueTo('a');
          expect(function() {$browser.defer.flush();}).toThrowError('No deferred tasks to be flushed');
          expect(watchSpy).not.toHaveBeenCalled();

          $timeout.flush(10000);
          expect(watchSpy).toHaveBeenCalled();
        }));


        it('should allow selecting different debounce timeouts for each event',
          function() {
          var inputElm = helper.compileInput(
              '<input type="text" ng-model="name" name="alias" ' +
                'ng-model-options="{' +
                  'updateOn: \'default blur mouseup\', ' +
                  'debounce: { default: 10000, blur: 5000 }' +
                '}"' +
              '/>');

          helper.changeInputValueTo('a');
          expect($rootScope.name).toBeUndefined();
          $timeout.flush(6000);
          expect($rootScope.name).toBeUndefined();
          $timeout.flush(4000);
          expect($rootScope.name).toEqual('a');

          helper.changeInputValueTo('b');

Review comment (suggestion):
This doesn't work correctly. It still flushes the task and triggers a digest. I haven't found out why exactly it doesn't work, but I suspect it's because of a mismatch between the real browser and the mock browser.

Code after:
                'ng-model-options="{ debounce: 30000 }"' +
              '/>');

          browserTrigger(inputElm[0], 'click');
          expect($rootScope.color).toBe('white');
          browserTrigger(inputElm[1], 'click');
          expect($rootScope.color).toBe('white');
          $timeout.flush(12000);
          expect($rootScope.color).toBe('white');
          $timeout.flush(10000);
          expect($rootScope.color).toBe('red');

        });


        it('should not trigger digest while debouncing', function() {
          var inputElm = helper.compileInput(
              '<input type="text" ng-model="name" name="alias" ' +
                'ng-model-options="{ debounce: 10000 }"' +
              '/>');

          var watchSpy = jasmine.createSpy('watchSpy');
          $rootScope.$watch(watchSpy);

          helper.changeInputValueTo('a');
          $timeout.flush(2000);
          expect(watchSpy).not.toHaveBeenCalled();

          helper.changeInputValueTo('b');
          $timeout.flush(2000);
          expect(watchSpy).not.toHaveBeenCalled();

          helper.changeInputValueTo('c');
          $timeout.flush(10000);
          expect(watchSpy).toHaveBeenCalled();
        });


        it('should allow selecting different debounce timeouts for each event',
          function() {
          var inputElm = helper.compileInput(
              '<input type="text" ng-model="name" name="alias" ' +
                'ng-model-options="{' +
                  'updateOn: \'default blur mouseup\', ' +
                  'debounce: { default: 10000, blur: 5000 }' +
                '}"' +
              '/>');

          helper.changeInputValueTo('a');
          expect($rootScope.name).toBeUndefined();
          $timeout.flush(6000);