Last active
August 29, 2015 14:08
-
-
Save lancecaraccioli/fa6b0977f27d7b1ff9ab to your computer and use it in GitHub Desktop.
Jasmine spy + AngularJS $timeout = lodash.debounce mock for AngularJS unit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @description | |
| * Rudimentary mock of lodash.debounce, which assumes the default debounce options | |
| * - Jasmine 2.0.0 | |
| * - lodash 2.4.1 | |
| * - AngularJS 1.3.0 | |
| */ | |
| function mockLodashDebounceForAngularJS(fn, ms) { | |
| var callPromise; | |
| return function () { | |
| $timeout.cancel(callPromise); | |
| //console.info('debounce "' + fn.name + '" ' + ms + 'ms'); | |
| callPromise = $timeout(fn, ms); | |
| /*callPromise.then(function () { | |
| console.info(fn.name + ' was called after debounce of ' + ms + 'ms'); | |
| });*/ | |
| }; | |
| } | |
| //via jasmine spyOn | |
| spyOn(_, 'debounce').and.callFake(mockLodashDebounceForAngularJS); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment