react / wstein / node_modules / jest-cli / node_modules / cover / node_modules / underscore.string / test / test_underscore / objects.js
80684 views$(document).ready(function() {12module("Objects");34test("objects: keys", function() {5var exception = /object/;6equals(_.keys({one : 1, two : 2}).join(', '), 'one, two', 'can extract the keys from an object');7// the test above is not safe because it relies on for-in enumeration order8var a = []; a[1] = 0;9equals(_.keys(a).join(', '), '1', 'is not fooled by sparse arrays; see issue #95');10raises(function() { _.keys(null); }, exception, 'throws an error for `null` values');11raises(function() { _.keys(void 0); }, exception, 'throws an error for `undefined` values');12raises(function() { _.keys(1); }, exception, 'throws an error for number primitives');13raises(function() { _.keys('a'); }, exception, 'throws an error for string primitives');14raises(function() { _.keys(true); }, exception, 'throws an error for boolean primitives');15});1617test("objects: values", function() {18equals(_.values({one : 1, two : 2}).join(', '), '1, 2', 'can extract the values from an object');19});2021test("objects: functions", function() {22var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce};23ok(_.isEqual(['b', 'd'], _.functions(obj)), 'can grab the function names of any passed-in object');2425var Animal = function(){};26Animal.prototype.run = function(){};27equals(_.functions(new Animal).join(''), 'run', 'also looks up functions on the prototype');28});2930test("objects: extend", function() {31var result;32equals(_.extend({}, {a:'b'}).a, 'b', 'can extend an object with the attributes of another');33equals(_.extend({a:'x'}, {a:'b'}).a, 'b', 'properties in source override destination');34equals(_.extend({x:'x'}, {a:'b'}).x, 'x', 'properties not in source dont get overriden');35result = _.extend({x:'x'}, {a:'a'}, {b:'b'});36ok(_.isEqual(result, {x:'x', a:'a', b:'b'}), 'can extend from multiple source objects');37result = _.extend({x:'x'}, {a:'a', x:2}, {a:'b'});38ok(_.isEqual(result, {x:2, a:'b'}), 'extending from multiple source objects last property trumps');39result = _.extend({}, {a: void 0, b: null});40equals(_.keys(result).join(''), 'b', 'extend does not copy undefined values');41});4243test("objects: defaults", function() {44var result;45var options = {zero: 0, one: 1, empty: "", nan: NaN, string: "string"};4647_.defaults(options, {zero: 1, one: 10, twenty: 20});48equals(options.zero, 0, 'value exists');49equals(options.one, 1, 'value exists');50equals(options.twenty, 20, 'default applied');5152_.defaults(options, {empty: "full"}, {nan: "nan"}, {word: "word"}, {word: "dog"});53equals(options.empty, "", 'value exists');54ok(_.isNaN(options.nan), "NaN isn't overridden");55equals(options.word, "word", 'new value is added, first one wins');56});5758test("objects: clone", function() {59var moe = {name : 'moe', lucky : [13, 27, 34]};60var clone = _.clone(moe);61equals(clone.name, 'moe', 'the clone as the attributes of the original');6263clone.name = 'curly';64ok(clone.name == 'curly' && moe.name == 'moe', 'clones can change shallow attributes without affecting the original');6566clone.lucky.push(101);67equals(_.last(moe.lucky), 101, 'changes to deep attributes are shared with the original');6869equals(_.clone(undefined), void 0, 'non objects should not be changed by clone');70equals(_.clone(1), 1, 'non objects should not be changed by clone');71equals(_.clone(null), null, 'non objects should not be changed by clone');72});7374test("objects: isEqual", function() {75function First() {76this.value = 1;77}78First.prototype.value = 1;79function Second() {80this.value = 1;81}82Second.prototype.value = 2;8384// Basic equality and identity comparisons.85ok(_.isEqual(null, null), "`null` is equal to `null`");86ok(_.isEqual(), "`undefined` is equal to `undefined`");8788ok(!_.isEqual(0, -0), "`0` is not equal to `-0`");89ok(!_.isEqual(-0, 0), "Commutative equality is implemented for `0` and `-0`");90ok(!_.isEqual(null, undefined), "`null` is not equal to `undefined`");91ok(!_.isEqual(undefined, null), "Commutative equality is implemented for `null` and `undefined`");9293// String object and primitive comparisons.94ok(_.isEqual("Curly", "Curly"), "Identical string primitives are equal");95ok(_.isEqual(new String("Curly"), new String("Curly")), "String objects with identical primitive values are equal");9697ok(!_.isEqual("Curly", "Larry"), "String primitives with different values are not equal");98ok(!_.isEqual(new String("Curly"), "Curly"), "String primitives and their corresponding object wrappers are not equal");99ok(!_.isEqual("Curly", new String("Curly")), "Commutative equality is implemented for string objects and primitives");100ok(!_.isEqual(new String("Curly"), new String("Larry")), "String objects with different primitive values are not equal");101ok(!_.isEqual(new String("Curly"), {toString: function(){ return "Curly"; }}), "String objects and objects with a custom `toString` method are not equal");102103// Number object and primitive comparisons.104ok(_.isEqual(75, 75), "Identical number primitives are equal");105ok(_.isEqual(new Number(75), new Number(75)), "Number objects with identical primitive values are equal");106107ok(!_.isEqual(75, new Number(75)), "Number primitives and their corresponding object wrappers are not equal");108ok(!_.isEqual(new Number(75), 75), "Commutative equality is implemented for number objects and primitives");109ok(!_.isEqual(new Number(75), new Number(63)), "Number objects with different primitive values are not equal");110ok(!_.isEqual(new Number(63), {valueOf: function(){ return 63; }}), "Number objects and objects with a `valueOf` method are not equal");111112// Comparisons involving `NaN`.113ok(_.isEqual(NaN, NaN), "`NaN` is equal to `NaN`");114ok(!_.isEqual(61, NaN), "A number primitive is not equal to `NaN`");115ok(!_.isEqual(new Number(79), NaN), "A number object is not equal to `NaN`");116ok(!_.isEqual(Infinity, NaN), "`Infinity` is not equal to `NaN`");117118// Boolean object and primitive comparisons.119ok(_.isEqual(true, true), "Identical boolean primitives are equal");120ok(_.isEqual(new Boolean, new Boolean), "Boolean objects with identical primitive values are equal");121ok(!_.isEqual(true, new Boolean(true)), "Boolean primitives and their corresponding object wrappers are not equal");122ok(!_.isEqual(new Boolean(true), true), "Commutative equality is implemented for booleans");123ok(!_.isEqual(new Boolean(true), new Boolean), "Boolean objects with different primitive values are not equal");124125// Common type coercions.126ok(!_.isEqual(true, new Boolean(false)), "Boolean objects are not equal to the boolean primitive `true`");127ok(!_.isEqual("75", 75), "String and number primitives with like values are not equal");128ok(!_.isEqual(new Number(63), new String(63)), "String and number objects with like values are not equal");129ok(!_.isEqual(75, "75"), "Commutative equality is implemented for like string and number values");130ok(!_.isEqual(0, ""), "Number and string primitives with like values are not equal");131ok(!_.isEqual(1, true), "Number and boolean primitives with like values are not equal");132ok(!_.isEqual(new Boolean(false), new Number(0)), "Boolean and number objects with like values are not equal");133ok(!_.isEqual(false, new String("")), "Boolean primitives and string objects with like values are not equal");134ok(!_.isEqual(12564504e5, new Date(2009, 9, 25)), "Dates and their corresponding numeric primitive values are not equal");135136// Dates.137ok(_.isEqual(new Date(2009, 9, 25), new Date(2009, 9, 25)), "Date objects referencing identical times are equal");138ok(!_.isEqual(new Date(2009, 9, 25), new Date(2009, 11, 13)), "Date objects referencing different times are not equal");139ok(!_.isEqual(new Date(2009, 11, 13), {140getTime: function(){141return 12606876e5;142}143}), "Date objects and objects with a `getTime` method are not equal");144ok(!_.isEqual(new Date("Curly"), new Date("Curly")), "Invalid dates are not equal");145146// Functions.147ok(!_.isEqual(First, Second), "Different functions with identical bodies and source code representations are not equal");148149// RegExps.150ok(_.isEqual(/(?:)/gim, /(?:)/gim), "RegExps with equivalent patterns and flags are equal");151ok(!_.isEqual(/(?:)/g, /(?:)/gi), "RegExps with equivalent patterns and different flags are not equal");152ok(!_.isEqual(/Moe/gim, /Curly/gim), "RegExps with different patterns and equivalent flags are not equal");153ok(!_.isEqual(/(?:)/gi, /(?:)/g), "Commutative equality is implemented for RegExps");154ok(!_.isEqual(/Curly/g, {source: "Larry", global: true, ignoreCase: false, multiline: false}), "RegExps and RegExp-like objects are not equal");155156// Empty arrays, array-like objects, and object literals.157ok(_.isEqual({}, {}), "Empty object literals are equal");158ok(_.isEqual([], []), "Empty array literals are equal");159ok(_.isEqual([{}], [{}]), "Empty nested arrays and objects are equal");160ok(!_.isEqual({length: 0}, []), "Array-like objects and arrays are not equal.");161ok(!_.isEqual([], {length: 0}), "Commutative equality is implemented for array-like objects");162163ok(!_.isEqual({}, []), "Object literals and array literals are not equal");164ok(!_.isEqual([], {}), "Commutative equality is implemented for objects and arrays");165166// Arrays with primitive and object values.167ok(_.isEqual([1, "Larry", true], [1, "Larry", true]), "Arrays containing identical primitives are equal");168ok(_.isEqual([/Moe/g, new Date(2009, 9, 25)], [/Moe/g, new Date(2009, 9, 25)]), "Arrays containing equivalent elements are equal");169170// Multi-dimensional arrays.171var a = [new Number(47), false, "Larry", /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}];172var b = [new Number(47), false, "Larry", /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}];173ok(_.isEqual(a, b), "Arrays containing nested arrays and objects are recursively compared");174175// Overwrite the methods defined in ES 5.1 section 15.4.4.176a.forEach = a.map = a.filter = a.every = a.indexOf = a.lastIndexOf = a.some = a.reduce = a.reduceRight = null;177b.join = b.pop = b.reverse = b.shift = b.slice = b.splice = b.concat = b.sort = b.unshift = null;178179// Array elements and properties.180ok(!_.isEqual(a, b), "Arrays containing equivalent elements and different non-numeric properties are not equal");181a.push("White Rocks");182ok(!_.isEqual(a, b), "Arrays of different lengths are not equal");183a.push("East Boulder");184b.push("Gunbarrel Ranch", "Teller Farm");185ok(!_.isEqual(a, b), "Arrays of identical lengths containing different elements are not equal");186187// Sparse arrays.188ok(_.isEqual(Array(3), Array(3)), "Sparse arrays of identical lengths are equal");189ok(!_.isEqual(Array(3), Array(6)), "Sparse arrays of different lengths are not equal when both are empty");190191// According to the Microsoft deviations spec, section 2.1.26, JScript 5.x treats `undefined`192// elements in arrays as elisions. Thus, sparse arrays and dense arrays containing `undefined`193// values are equivalent.194if (0 in [undefined]) {195ok(!_.isEqual(Array(3), [undefined, undefined, undefined]), "Sparse and dense arrays are not equal");196ok(!_.isEqual([undefined, undefined, undefined], Array(3)), "Commutative equality is implemented for sparse and dense arrays");197}198199// Simple objects.200ok(_.isEqual({a: "Curly", b: 1, c: true}, {a: "Curly", b: 1, c: true}), "Objects containing identical primitives are equal");201ok(_.isEqual({a: /Curly/g, b: new Date(2009, 11, 13)}, {a: /Curly/g, b: new Date(2009, 11, 13)}), "Objects containing equivalent members are equal");202ok(!_.isEqual({a: 63, b: 75}, {a: 61, b: 55}), "Objects of identical sizes with different values are not equal");203ok(!_.isEqual({a: 63, b: 75}, {a: 61, c: 55}), "Objects of identical sizes with different property names are not equal");204ok(!_.isEqual({a: 1, b: 2}, {a: 1}), "Objects of different sizes are not equal");205ok(!_.isEqual({a: 1}, {a: 1, b: 2}), "Commutative equality is implemented for objects");206ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), "Objects with identical keys and different values are not equivalent");207208// `A` contains nested objects and arrays.209a = {210name: new String("Moe Howard"),211age: new Number(77),212stooge: true,213hobbies: ["acting"],214film: {215name: "Sing a Song of Six Pants",216release: new Date(1947, 9, 30),217stars: [new String("Larry Fine"), "Shemp Howard"],218minutes: new Number(16),219seconds: 54220}221};222223// `B` contains equivalent nested objects and arrays.224b = {225name: new String("Moe Howard"),226age: new Number(77),227stooge: true,228hobbies: ["acting"],229film: {230name: "Sing a Song of Six Pants",231release: new Date(1947, 9, 30),232stars: [new String("Larry Fine"), "Shemp Howard"],233minutes: new Number(16),234seconds: 54235}236};237ok(_.isEqual(a, b), "Objects with nested equivalent members are recursively compared");238239// Instances.240ok(_.isEqual(new First, new First), "Object instances are equal");241ok(!_.isEqual(new First, new Second), "Objects with different constructors and identical own properties are not equal");242ok(!_.isEqual({value: 1}, new First), "Object instances and objects sharing equivalent properties are not identical");243ok(!_.isEqual({value: 2}, new Second), "The prototype chain of objects should not be examined");244245// Circular Arrays.246(a = []).push(a);247(b = []).push(b);248ok(_.isEqual(a, b), "Arrays containing circular references are equal");249a.push(new String("Larry"));250b.push(new String("Larry"));251ok(_.isEqual(a, b), "Arrays containing circular references and equivalent properties are equal");252a.push("Shemp");253b.push("Curly");254ok(!_.isEqual(a, b), "Arrays containing circular references and different properties are not equal");255256// Circular Objects.257a = {abc: null};258b = {abc: null};259a.abc = a;260b.abc = b;261ok(_.isEqual(a, b), "Objects containing circular references are equal");262a.def = 75;263b.def = 75;264ok(_.isEqual(a, b), "Objects containing circular references and equivalent properties are equal");265a.def = new Number(75);266b.def = new Number(63);267ok(!_.isEqual(a, b), "Objects containing circular references and different properties are not equal");268269// Cyclic Structures.270a = [{abc: null}];271b = [{abc: null}];272(a[0].abc = a).push(a);273(b[0].abc = b).push(b);274ok(_.isEqual(a, b), "Cyclic structures are equal");275a[0].def = "Larry";276b[0].def = "Larry";277ok(_.isEqual(a, b), "Cyclic structures containing equivalent properties are equal");278a[0].def = new String("Larry");279b[0].def = new String("Curly");280ok(!_.isEqual(a, b), "Cyclic structures containing different properties are not equal");281282// Complex Circular References.283a = {foo: {b: {foo: {c: {foo: null}}}}};284b = {foo: {b: {foo: {c: {foo: null}}}}};285a.foo.b.foo.c.foo = a;286b.foo.b.foo.c.foo = b;287ok(_.isEqual(a, b), "Cyclic structures with nested and identically-named properties are equal");288289// Chaining.290ok(!_.isEqual(_({x: 1, y: undefined}).chain(), _({x: 1, z: 2}).chain()), 'Chained objects containing different values are not equal');291equals(_({x: 1, y: 2}).chain().isEqual(_({x: 1, y: 2}).chain()).value(), true, '`isEqual` can be chained');292293// Custom `isEqual` methods.294var isEqualObj = {isEqual: function (o) { return o.isEqual == this.isEqual; }, unique: {}};295var isEqualObjClone = {isEqual: isEqualObj.isEqual, unique: {}};296297ok(_.isEqual(isEqualObj, isEqualObjClone), 'Both objects implement identical `isEqual` methods');298ok(_.isEqual(isEqualObjClone, isEqualObj), 'Commutative equality is implemented for objects with custom `isEqual` methods');299ok(!_.isEqual(isEqualObj, {}), 'Objects that do not implement equivalent `isEqual` methods are not equal');300ok(!_.isEqual({}, isEqualObj), 'Commutative equality is implemented for objects with different `isEqual` methods');301302// Custom `isEqual` methods - comparing different types303LocalizedString = (function() {304function LocalizedString(id) { this.id = id; this.string = (this.id===10)? 'Bonjour': ''; }305LocalizedString.prototype.isEqual = function(that) {306if (_.isString(that)) return this.string == that;307else if (that instanceof LocalizedString) return this.id == that.id;308return false;309};310return LocalizedString;311})();312var localized_string1 = new LocalizedString(10), localized_string2 = new LocalizedString(10), localized_string3 = new LocalizedString(11);313ok(_.isEqual(localized_string1, localized_string2), 'comparing same typed instances with same ids');314ok(!_.isEqual(localized_string1, localized_string3), 'comparing same typed instances with different ids');315ok(_.isEqual(localized_string1, 'Bonjour'), 'comparing different typed instances with same values');316ok(_.isEqual('Bonjour', localized_string1), 'comparing different typed instances with same values');317ok(!_.isEqual('Bonjour', localized_string3), 'comparing two localized strings with different ids');318ok(!_.isEqual(localized_string1, 'Au revoir'), 'comparing different typed instances with different values');319ok(!_.isEqual('Au revoir', localized_string1), 'comparing different typed instances with different values');320321// Custom `isEqual` methods - comparing with serialized data322Date.prototype.toJSON = function() {323return {324_type:'Date',325year:this.getUTCFullYear(),326month:this.getUTCMonth(),327day:this.getUTCDate(),328hours:this.getUTCHours(),329minutes:this.getUTCMinutes(),330seconds:this.getUTCSeconds()331};332};333Date.prototype.isEqual = function(that) {334var this_date_components = this.toJSON();335var that_date_components = (that instanceof Date) ? that.toJSON() : that;336delete this_date_components['_type']; delete that_date_components['_type']337return _.isEqual(this_date_components, that_date_components);338};339340var date = new Date();341var date_json = {342_type:'Date',343year:date.getUTCFullYear(),344month:date.getUTCMonth(),345day:date.getUTCDate(),346hours:date.getUTCHours(),347minutes:date.getUTCMinutes(),348seconds:date.getUTCSeconds()349};350351ok(_.isEqual(date_json, date), 'serialized date matches date');352ok(_.isEqual(date, date_json), 'date matches serialized date');353});354355test("objects: isEmpty", function() {356ok(!_([1]).isEmpty(), '[1] is not empty');357ok(_.isEmpty([]), '[] is empty');358ok(!_.isEmpty({one : 1}), '{one : 1} is not empty');359ok(_.isEmpty({}), '{} is empty');360ok(_.isEmpty(new RegExp('')), 'objects with prototype properties are empty');361ok(_.isEmpty(null), 'null is empty');362ok(_.isEmpty(), 'undefined is empty');363ok(_.isEmpty(''), 'the empty string is empty');364ok(!_.isEmpty('moe'), 'but other strings are not');365366var obj = {one : 1};367delete obj.one;368ok(_.isEmpty(obj), 'deleting all the keys from an object empties it');369});370371// Setup remote variables for iFrame tests.372var iframe = document.createElement('iframe');373jQuery(iframe).appendTo(document.body);374var iDoc = iframe.contentDocument || iframe.contentWindow.document;375iDoc.write(376"<script>\377parent.iElement = document.createElement('div');\378parent.iArguments = (function(){ return arguments; })(1, 2, 3);\379parent.iArray = [1, 2, 3];\380parent.iString = new String('hello');\381parent.iNumber = new Number(100);\382parent.iFunction = (function(){});\383parent.iDate = new Date();\384parent.iRegExp = /hi/;\385parent.iNaN = NaN;\386parent.iNull = null;\387parent.iBoolean = new Boolean(false);\388parent.iUndefined = undefined;\389</script>"390);391iDoc.close();392393test("objects: isElement", function() {394ok(!_.isElement('div'), 'strings are not dom elements');395ok(_.isElement($('html')[0]), 'the html tag is a DOM element');396ok(_.isElement(iElement), 'even from another frame');397});398399test("objects: isArguments", function() {400var args = (function(){ return arguments; })(1, 2, 3);401ok(!_.isArguments('string'), 'a string is not an arguments object');402ok(!_.isArguments(_.isArguments), 'a function is not an arguments object');403ok(_.isArguments(args), 'but the arguments object is an arguments object');404ok(!_.isArguments(_.toArray(args)), 'but not when it\'s converted into an array');405ok(!_.isArguments([1,2,3]), 'and not vanilla arrays.');406ok(_.isArguments(iArguments), 'even from another frame');407});408409test("objects: isObject", function() {410ok(_.isObject(arguments), 'the arguments object is object');411ok(_.isObject([1, 2, 3]), 'and arrays');412ok(_.isObject($('html')[0]), 'and DOM element');413ok(_.isObject(iElement), 'even from another frame');414ok(_.isObject(function () {}), 'and functions');415ok(_.isObject(iFunction), 'even from another frame');416ok(!_.isObject(null), 'but not null');417ok(!_.isObject(undefined), 'and not undefined');418ok(!_.isObject('string'), 'and not string');419ok(!_.isObject(12), 'and not number');420ok(!_.isObject(true), 'and not boolean');421ok(_.isObject(new String('string')), 'but new String()');422});423424test("objects: isArray", function() {425ok(!_.isArray(arguments), 'the arguments object is not an array');426ok(_.isArray([1, 2, 3]), 'but arrays are');427ok(_.isArray(iArray), 'even from another frame');428});429430test("objects: isString", function() {431ok(!_.isString(document.body), 'the document body is not a string');432ok(_.isString([1, 2, 3].join(', ')), 'but strings are');433ok(_.isString(iString), 'even from another frame');434});435436test("objects: isNumber", function() {437ok(!_.isNumber('string'), 'a string is not a number');438ok(!_.isNumber(arguments), 'the arguments object is not a number');439ok(!_.isNumber(undefined), 'undefined is not a number');440ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are');441ok(_.isNumber(NaN), 'NaN *is* a number');442ok(_.isNumber(Infinity), 'Infinity is a number');443ok(_.isNumber(iNumber), 'even from another frame');444ok(!_.isNumber('1'), 'numeric strings are not numbers');445});446447test("objects: isBoolean", function() {448ok(!_.isBoolean(2), 'a number is not a boolean');449ok(!_.isBoolean("string"), 'a string is not a boolean');450ok(!_.isBoolean("false"), 'the string "false" is not a boolean');451ok(!_.isBoolean("true"), 'the string "true" is not a boolean');452ok(!_.isBoolean(arguments), 'the arguments object is not a boolean');453ok(!_.isBoolean(undefined), 'undefined is not a boolean');454ok(!_.isBoolean(NaN), 'NaN is not a boolean');455ok(!_.isBoolean(null), 'null is not a boolean');456ok(_.isBoolean(true), 'but true is');457ok(_.isBoolean(false), 'and so is false');458ok(_.isBoolean(iBoolean), 'even from another frame');459});460461test("objects: isFunction", function() {462ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');463ok(!_.isFunction('moe'), 'strings are not functions');464ok(_.isFunction(_.isFunction), 'but functions are');465ok(_.isFunction(iFunction), 'even from another frame');466});467468test("objects: isDate", function() {469ok(!_.isDate(100), 'numbers are not dates');470ok(!_.isDate({}), 'objects are not dates');471ok(_.isDate(new Date()), 'but dates are');472ok(_.isDate(iDate), 'even from another frame');473});474475test("objects: isRegExp", function() {476ok(!_.isRegExp(_.identity), 'functions are not RegExps');477ok(_.isRegExp(/identity/), 'but RegExps are');478ok(_.isRegExp(iRegExp), 'even from another frame');479});480481test("objects: isNaN", function() {482ok(!_.isNaN(undefined), 'undefined is not NaN');483ok(!_.isNaN(null), 'null is not NaN');484ok(!_.isNaN(0), '0 is not NaN');485ok(_.isNaN(NaN), 'but NaN is');486ok(_.isNaN(iNaN), 'even from another frame');487});488489test("objects: isNull", function() {490ok(!_.isNull(undefined), 'undefined is not null');491ok(!_.isNull(NaN), 'NaN is not null');492ok(_.isNull(null), 'but null is');493ok(_.isNull(iNull), 'even from another frame');494});495496test("objects: isUndefined", function() {497ok(!_.isUndefined(1), 'numbers are defined');498ok(!_.isUndefined(null), 'null is defined');499ok(!_.isUndefined(false), 'false is defined');500ok(!_.isUndefined(NaN), 'NaN is defined');501ok(_.isUndefined(), 'nothing is undefined');502ok(_.isUndefined(undefined), 'undefined is undefined');503ok(_.isUndefined(iUndefined), 'even from another frame');504});505506if (window.ActiveXObject) {507test("objects: IE host objects", function() {508var xml = new ActiveXObject("Msxml2.DOMDocument.3.0");509ok(!_.isNumber(xml));510ok(!_.isBoolean(xml));511ok(!_.isNaN(xml));512ok(!_.isFunction(xml));513ok(!_.isNull(xml));514ok(!_.isUndefined(xml));515});516}517518test("objects: tap", function() {519var intercepted = null;520var interceptor = function(obj) { intercepted = obj; };521var returned = _.tap(1, interceptor);522equals(intercepted, 1, "passes tapped object to interceptor");523equals(returned, 1, "returns tapped object");524525returned = _([1,2,3]).chain().526map(function(n){ return n * 2; }).527max().528tap(interceptor).529value();530ok(returned == 6 && intercepted == 6, 'can use tapped objects in a chain');531});532});533534535