Skip to content

Commit ea4252e

Browse files
committed
Test two of the utility functions and fix a bug that was found.
1 parent f4c8212 commit ea4252e

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,14 @@
21072107
}
21082108
};
21092109

2110+
/*
2111+
* Add util object to allow access to private methods for testability.
2112+
*/
2113+
$.timepicker.util = {
2114+
_extendRemove: extendRemove,
2115+
_isEmptyObject: isEmptyObject
2116+
};
2117+
21102118
/*
21112119
* Microsecond support
21122120
*/
Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,69 @@
11
describe('datetimepicker', function() {
2-
it('should fail', function() {
3-
expect(true).toBe(false);
2+
describe('utility functions', function() {
3+
var util = $.timepicker.util;
4+
5+
describe('extendRemove', function() {
6+
var target,
7+
props;
8+
9+
beforeEach(function() {
10+
target = {};
11+
props = {};
12+
});
13+
14+
it('should add a nonexistent property to the target', function() {
15+
var expectedValue = "set",
16+
propertyName = "prop";
17+
props[propertyName] = expectedValue;
18+
19+
var newTarget = util._extendRemove(target, props);
20+
21+
expect(target[propertyName]).toBe(expectedValue);
22+
expect(newTarget).toBe(target);
23+
});
24+
25+
it('should change the value of an existing property', function() {
26+
var expectedValue = "new",
27+
originalValue = "old",
28+
propertyName = "prop";
29+
target[propertyName] = originalValue;
30+
props[propertyName] = expectedValue;
31+
32+
util._extendRemove(target, props);
33+
34+
expect(target[propertyName]).not.toBe(originalValue);
35+
expect(target[propertyName]).toBe(expectedValue);
36+
});
37+
38+
it('should null the value of an existing property', function() {
39+
var expectedValue = null,
40+
propertyName = "prop";
41+
target[propertyName] = "original";
42+
props[propertyName] = expectedValue;
43+
44+
util._extendRemove(target, props);
45+
46+
expect(target[propertyName]).toBeNull();
47+
});
48+
});
49+
50+
describe('isEmptyObject', function() {
51+
it('should say an empty object is empty', function() {
52+
expect(util._isEmptyObject({})).toBe(true);
53+
});
54+
55+
it('should say an object with a property is not empty', function() {
56+
var testObject = {"prop": "value"};
57+
58+
expect(util._isEmptyObject(testObject)).toBe(false);
59+
});
60+
61+
it('should say object with a supplemental prototype property is empty', function() {
62+
var testObject = new Function();
63+
testObject.prototype["prop"] = "something";
64+
65+
expect(util._isEmptyObject(testObject)).toBe(true);
66+
})
67+
});
468
});
569
});

0 commit comments

Comments
 (0)