Permalink
Browse files

added a few more test cases

  • Loading branch information...
1 parent 7cafb54 commit 5656ba23cbe6a610d9452d541342332dad9d1cf4 @clottes committed Feb 6, 2013
Showing with 11 additions and 1 deletion.
  1. +3 −1 test/collections.js
  2. +8 −0 test/objects.js
View
@@ -438,14 +438,16 @@ $(document).ready(function() {
test('size', function() {
equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
equal(_.size([1, 2, 3]), 3, 'can compute the size of an array');
+ equal(_.size($('<div>').add('<span>').add('<span>')), 3, 'can compute the size of jQuery objects');
var func = function() {
return _.size(arguments);
};
equal(func(1, 2, 3, 4), 4, 'can test the size of the arguments object');
- equal(_.size('hello'), 5, 'can compute the size of a string');
+ equal(_.size('hello'), 5, 'can compute the size of a string literal');
+ equal(_.size(new String('hello')), 5, 'can compute the size of string object');
equal(_.size(null), 0, 'handles nulls');
});
View
@@ -2,6 +2,8 @@ $(document).ready(function() {
module("Objects");
+ var undefined; //ensure undefined is really undefined
+
test("keys", function() {
equal(_.keys({one : 1, two : 2}).join(', '), 'one, two', 'can extract the keys from an object');
// the test above is not safe because it relies on for-in enumeration order
@@ -431,15 +433,19 @@ $(document).ready(function() {
});
test("isArray", function() {
+ ok(!_.isArray(undefined), 'undefined vars are not arrays');
ok(!_.isArray(arguments), 'the arguments object is not an array');
ok(_.isArray([1, 2, 3]), 'but arrays are');
ok(_.isArray(iArray), 'even from another frame');
});
test("isString", function() {
+ var obj = new String("I am a string object");
ok(!_.isString(document.body), 'the document body is not a string');
ok(_.isString([1, 2, 3].join(', ')), 'but strings are');
ok(_.isString(iString), 'even from another frame');
+ ok(_.isString("I am a string literal"), 'string literals are');
+ ok(_.isString(obj), 'so are String objects');
});
test("isNumber", function() {
@@ -468,10 +474,12 @@ $(document).ready(function() {
});
test("isFunction", function() {
+ ok(!_.isFunction(undefined), 'undefined vars are not functions');
ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');
ok(!_.isFunction('moe'), 'strings are not functions');
ok(_.isFunction(_.isFunction), 'but functions are');
ok(_.isFunction(iFunction), 'even from another frame');
+ ok(_.isFunction(function(){}), 'even anonymous ones');
});
test("isDate", function() {

0 comments on commit 5656ba2

Please sign in to comment.