From 169565ae1804bc58c694ab5f8ccec9d6e0f34845 Mon Sep 17 00:00:00 2001 From: Astashenkau Date: Tue, 10 Nov 2015 15:15:56 +0100 Subject: [PATCH] fix(debounce): Properly pass arguments to debounced function Closes #4859 --- src/debounce/debounce.js | 4 ++-- src/debounce/test/debounce.spec.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/debounce/debounce.js b/src/debounce/debounce.js index 751795702c..28ff4f798a 100644 --- a/src/debounce/debounce.js +++ b/src/debounce/debounce.js @@ -8,7 +8,7 @@ angular.module('ui.bootstrap.debounce', []) return function() { var self = this; - var args = Array.prototype.slice(arguments); + var args = Array.prototype.slice.call(arguments); if (timeoutPromise) { $timeout.cancel(timeoutPromise); } @@ -18,4 +18,4 @@ angular.module('ui.bootstrap.debounce', []) }, debounceTime); }; }; - }]); \ No newline at end of file + }]); diff --git a/src/debounce/test/debounce.spec.js b/src/debounce/test/debounce.spec.js index 6b67f61627..b220350299 100644 --- a/src/debounce/test/debounce.spec.js +++ b/src/debounce/test/debounce.spec.js @@ -1,5 +1,5 @@ describe('$$debounce', function() { - var $$debounce, $timeout, debouncedFunction, i; + var $$debounce, $timeout, debouncedFunction, i, args; beforeEach(module('ui.bootstrap.debounce')); beforeEach(inject(function(_$$debounce_, _$timeout_) { @@ -7,6 +7,7 @@ describe('$$debounce', function() { $timeout = _$timeout_; i = 0; debouncedFunction = $$debounce(function() { + args = Array.prototype.slice.call(arguments); i++; }, 100); })); @@ -37,4 +38,11 @@ describe('$$debounce', function() { expect(i).toBe(1); }); + + it('should properly pass arguments to debounced function', function() { + debouncedFunction(1, 2, 3); + $timeout.flush(100); + + expect(args).toEqual([1, 2, 3]); + }); });