diff options
author | Stephen Vance <steve@vance.com> | 2013-07-06 17:09:23 -0400 |
---|---|---|
committer | Stephen Vance <steve@vance.com> | 2013-07-06 22:19:52 -0400 |
commit | ea4252ea21bb010eec88d9377d71ade2aa85d90e (patch) | |
tree | ebfd0717fdf599f56e34221d30a86b14cdd2bf61 | |
parent | f4c82120a67e83ed78ca83cd01c971a9b1295cf9 (diff) | |
download | jQuery-Timepicker-Addon-ea4252ea21bb010eec88d9377d71ade2aa85d90e.zip jQuery-Timepicker-Addon-ea4252ea21bb010eec88d9377d71ade2aa85d90e.tar.gz jQuery-Timepicker-Addon-ea4252ea21bb010eec88d9377d71ade2aa85d90e.tar.bz2 |
Test two of the utility functions and fix a bug that was found.
-rw-r--r-- | jquery-ui-timepicker-addon.js | 8 | ||||
-rw-r--r-- | test/jquery-ui-timepicker-addon_spec.js | 68 |
2 files changed, 74 insertions, 2 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js index 1aca6b4..584244c 100644 --- a/jquery-ui-timepicker-addon.js +++ b/jquery-ui-timepicker-addon.js @@ -2108,6 +2108,14 @@ }; /* + * Add util object to allow access to private methods for testability. + */ + $.timepicker.util = { + _extendRemove: extendRemove, + _isEmptyObject: isEmptyObject + }; + + /* * Microsecond support */ if(!Date.prototype.getMicroseconds){ diff --git a/test/jquery-ui-timepicker-addon_spec.js b/test/jquery-ui-timepicker-addon_spec.js index ac98228..94ee485 100644 --- a/test/jquery-ui-timepicker-addon_spec.js +++ b/test/jquery-ui-timepicker-addon_spec.js @@ -1,5 +1,69 @@ describe('datetimepicker', function() { - it('should fail', function() { - expect(true).toBe(false); + describe('utility functions', function() { + var util = $.timepicker.util; + + describe('extendRemove', function() { + var target, + props; + + beforeEach(function() { + target = {}; + props = {}; + }); + + it('should add a nonexistent property to the target', function() { + var expectedValue = "set", + propertyName = "prop"; + props[propertyName] = expectedValue; + + var newTarget = util._extendRemove(target, props); + + expect(target[propertyName]).toBe(expectedValue); + expect(newTarget).toBe(target); + }); + + it('should change the value of an existing property', function() { + var expectedValue = "new", + originalValue = "old", + propertyName = "prop"; + target[propertyName] = originalValue; + props[propertyName] = expectedValue; + + util._extendRemove(target, props); + + expect(target[propertyName]).not.toBe(originalValue); + expect(target[propertyName]).toBe(expectedValue); + }); + + it('should null the value of an existing property', function() { + var expectedValue = null, + propertyName = "prop"; + target[propertyName] = "original"; + props[propertyName] = expectedValue; + + util._extendRemove(target, props); + + expect(target[propertyName]).toBeNull(); + }); + }); + + describe('isEmptyObject', function() { + it('should say an empty object is empty', function() { + expect(util._isEmptyObject({})).toBe(true); + }); + + it('should say an object with a property is not empty', function() { + var testObject = {"prop": "value"}; + + expect(util._isEmptyObject(testObject)).toBe(false); + }); + + it('should say object with a supplemental prototype property is empty', function() { + var testObject = new Function(); + testObject.prototype["prop"] = "something"; + + expect(util._isEmptyObject(testObject)).toBe(true); + }) + }); }); });
\ No newline at end of file |