Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / src / core / test / unit / spec / Ext.js
1 describe("Ext", function() {
2     
3     describe("Ext.global", function() {
4         it("should return the global scope", function() {
5             expect(Ext.global).toBe((function(){ return this;}).call());
6         });
7     });
8     
9     describe("Ext.apply", function() {
10         var origin, o;
11
12         beforeEach(function() {
13             origin = {
14                 name: 'value',
15                 something: 'cool',
16                 items: [1,2,3],
17                 method: function() {
18                     this.myMethodCalled = true;
19                 },
20                 toString: function() {
21                     this.myToStringCalled = true;
22                 }
23             };
24         });
25
26         it("should copy normal properties", function() {
27             Ext.apply(origin, {
28                 name: 'newName',
29                 items: [4,5,6],
30                 otherThing: 'not cool',
31                 isCool: false
32             });
33
34             expect(origin.name).toEqual('newName');
35             expect(origin.items).toEqual([4,5,6]);
36             expect(origin.something).toEqual('cool');
37             expect(origin.otherThing).toEqual('not cool');
38             expect(origin.isCool).toEqual(false);
39         });
40
41         it("should copy functions", function() {
42             Ext.apply(origin, {
43                 method: function() {
44                     this.newMethodCalled = true;
45                 }
46             });
47
48             origin.method();
49
50             expect(origin.myMethodCalled).not.toBeDefined();
51             expect(origin.newMethodCalled).toBeTruthy();
52         });
53
54         it("should copy non-enumerables", function() {
55             Ext.apply(origin, {
56                 toString: function() {
57                     this.newToStringCalled = true;
58                 }
59             });
60
61             origin.toString();
62
63             expect(origin.myToStringCalled).not.toBeDefined();
64             expect(origin.newToStringCalled).toBeTruthy();
65         });
66
67         it("should apply properties and return an object", function() {
68             o = Ext.apply({}, {
69                 foo: 1,
70                 bar: 2
71             });
72
73             expect(o).toEqual({
74                 foo: 1,
75                 bar: 2
76             });
77         });
78
79         it("should change the reference of the object", function() {
80             o = {};
81             Ext.apply(o, {
82                 opt1: 'x',
83                 opt2: 'y'
84             });
85
86             expect(o).toEqual({
87                 opt1: 'x',
88                 opt2: 'y'
89             });
90         });
91
92         it("should overwrite properties", function() {
93             o = Ext.apply({
94                 foo: 1,
95                 baz: 4
96             }, {
97                 foo: 2,
98                 bar: 3
99             });
100
101             expect(o).toEqual({
102                 foo: 2,
103                 bar: 3,
104                 baz: 4
105             });
106         });
107
108         it("should use default", function() {
109             o = {};
110
111             Ext.apply(o, {
112                 foo: 'new',
113                 exist: true
114             }, {
115                 foo: 'old',
116                 def: true
117             });
118
119             expect(o).toEqual({
120                 foo: 'new',
121                 def: true,
122                 exist: true
123             });
124         });
125
126         it("should override all defaults", function() {
127             o = Ext.apply({}, {
128                 foo: 'foo',
129                 bar: 'bar'
130             }, {
131                 foo: 'oldFoo',
132                 bar: 'oldBar'
133             });
134
135             expect(o).toEqual( {
136                 foo: 'foo',
137                 bar: 'bar'
138             });
139         });
140
141         it("should return null if null is passed as first argument", function() {
142            expect(Ext.apply(null, {})).toBeNull();
143         });
144
145         it("should return the object if second argument is no defined", function() {
146             o = {
147                 foo: 1
148             };
149             expect(Ext.apply(o)).toEqual(o);
150         });
151
152         it("should override valueOf", function() {
153             o = Ext.apply({}, {valueOf: 1});
154
155             expect(o.valueOf).toEqual(1);
156         });
157
158         it("should override toString", function() {
159             o = Ext.apply({}, {toString: 3});
160
161             expect(o.toString).toEqual(3);
162
163         });
164     });
165
166     describe("Ext.emptyFn", function() {
167         it("should return undefined without params", function() {
168             expect(Ext.emptyFn()).toBeUndefined();
169         });
170         
171         it("should return undefined if you pass params", function() {
172            expect(Ext.emptyFn('aaaa', 'bbbbb')).toBeUndefined(); 
173         });
174     });
175
176     describe("Ext.iterate", function() {
177         var itFn;
178
179         beforeEach(function() {
180             itFn = jasmine.createSpy();
181         });
182
183         describe("iterate object", function() {
184             var o;
185
186             beforeEach(function() {
187                 o = {
188                     n1: 11,
189                     n2: 13,
190                     n3: 18
191                 };
192             });
193
194             describe("if itFn does not return false", function() {
195                 beforeEach(function() {
196                     Ext.iterate(o, itFn);
197                 });
198
199                 it("should call the iterate function 3 times", function () {
200                     expect(itFn.callCount).toEqual(3);
201                 });
202
203                 it("should call the iterate function with correct arguments", function () {
204                     expect(itFn.calls[0].args).toEqual(["n1", 11, o]);
205                     expect(itFn.calls[1].args).toEqual(["n2", 13, o]);
206                     expect(itFn.calls[2].args).toEqual(["n3", 18, o]);
207                 });
208             });
209
210             describe("if itFn return false", function() {
211                 beforeEach(function() {
212                     itFn.andReturn(false);
213                     Ext.iterate(o, itFn);
214                 });
215
216                 it("should stop iteration if function return false", function() {
217                     itFn.andReturn(false);
218
219                     expect(itFn.calls.length).toEqual(1);
220                 });
221             });
222         });
223
224         describe("do nothing on an empty object", function() {
225             var o;
226
227             beforeEach(function() {
228                 o = {};
229                 Ext.iterate(o, itFn);
230             });
231
232             it("should not call the iterate function", function () {
233                 expect(itFn).not.toHaveBeenCalled();
234             });
235
236         });
237
238         describe("iterate array", function() {
239             var arr;
240
241             beforeEach(function() {
242                 arr = [6, 7, 8, 9];
243             });
244
245             describe("if itFn does not return false", function() {
246                 beforeEach(function() {
247                     Ext.iterate(arr, itFn);
248                 });
249
250                 it("should call the iterate function 4 times", function () {
251                     expect(itFn.callCount).toEqual(4);
252                 });
253
254                 it("should call the iterate function with correct arguments", function () {
255                     expect(itFn.calls[0].args).toEqual([6, 0, arr]);
256                     expect(itFn.calls[1].args).toEqual([7, 1, arr]);
257                     expect(itFn.calls[2].args).toEqual([8, 2, arr]);
258                     expect(itFn.calls[3].args).toEqual([9, 3, arr]);
259                 });
260              });
261
262             describe("if itFn return false", function() {
263                 beforeEach(function() {
264                     itFn.andReturn(false);
265                     Ext.iterate(arr, itFn);
266                 });
267
268                 it("should stop iteration if function return false", function() {
269                     itFn.andReturn(false);
270
271                     expect(itFn.calls.length).toEqual(1);
272                 });
273             });
274         });
275
276         describe("do nothing on an empty array", function() {
277             var arr;
278
279             beforeEach(function() {
280                 arr = [];
281                 Ext.iterate(arr, itFn);
282             });
283
284             it("should not call the iterate function", function () {
285                 expect(itFn).not.toHaveBeenCalled();
286             });
287
288         });
289     });
290
291     describe("Ext.applyIf", function(){
292         var o;
293
294         it("should apply properties and return an object with an empty destination object", function() {
295             o = Ext.applyIf({}, {
296                 foo: 'foo',
297                 bar: 'bar'
298             });
299
300             expect(o).toEqual( {
301                 foo: 'foo',
302                 bar: 'bar'
303             });
304         });
305
306         it("should not override default properties", function() {
307             o = Ext.applyIf({
308                 foo: 'foo'
309             }, {
310                 foo: 'oldFoo'
311             });
312
313             expect(o).toEqual({
314                 foo: 'foo'
315             });
316         });
317
318         it("should not override default properties with mixing properties", function() {
319             o = Ext.applyIf({
320                 foo: 1,
321                 bar: 2
322             }, {
323                 bar: 3,
324                 baz: 4
325             });
326
327             expect(o).toEqual({
328                 foo: 1,
329                 bar: 2,
330                 baz: 4
331             });
332         });
333
334           it("should change the reference of the object", function() {
335             o = {};
336             Ext.applyIf(o, {
337                 foo: 2
338             }, {
339                 foo: 1
340             });
341
342             expect(o).toEqual({
343                 foo: 2
344             });
345         });
346
347         it("should return null if null is passed as first argument", function() {
348            expect(Ext.applyIf(null, {})).toBeNull();
349         });
350
351         it("should return the object if second argument is no defined", function() {
352             o = {
353                 foo: 1
354             };
355
356             expect(Ext.applyIf(o)).toEqual(o);
357         });
358     });
359
360
361     describe("Ext.extend", function() {
362         var Dude, Awesome, david;
363
364         beforeEach(function() {
365             Dude = Ext.extend(Object, {
366                 constructor: function(config){
367                     Ext.apply(this, config);
368                     this.isBadass = false;
369                 }
370             });
371
372             Awesome = Ext.extend(Dude, {
373                 constructor: function(){
374                     Awesome.superclass.constructor.apply(this, arguments);
375                     this.isBadass = true;
376                 }
377             });
378
379             david = new Awesome({
380                 davis: 'isAwesome'
381             });
382         });
383
384         it("should throw an error if superclass isn't defined", function() {
385             expect(function() {
386                 Ext.extend(undefined, {});
387             }).toRaiseExtError("Attempting to extend from a class which has not been loaded on the page.");
388         });
389
390         it("should create a superclass that return the original classe", function() {
391             expect(david.superclass).toEqual(Dude.prototype);
392         });
393
394         it("should add override method", function() {
395             expect(typeof david.override === 'function').toBe(true);
396         });
397
398         it("should override redefined methods", function() {
399             expect(david.isBadass).toBe(true);
400         });
401
402         it("should keep new properties", function() {
403             expect(david.davis).toEqual('isAwesome');
404         });
405     });
406
407     describe("Ext.override", function(){
408         var Dude,
409             extApplySpy;
410
411         beforeEach(function(){
412             Dude = function(){}; // avoid to directly override Object class
413             extApplySpy = spyOn(Ext, "apply");
414         });
415
416         it("should apply override", function(){
417             var override = {foo: true};
418
419             Ext.override(Dude, override);
420
421             expect(extApplySpy).toHaveBeenCalledWith(Dude.prototype, override);
422         });
423     });
424
425     describe("Ext.valueFrom", function() {
426         var value, defaultValue;
427         
428         describe("with allowBlank", function() {
429             describe("and an empty string", function() {
430                 it("should return the value", function() {
431                     expect(Ext.valueFrom('', 'aaa', true)).toBe('');
432                 });
433             });
434             
435             describe("and a string", function() {
436                 it("should return the value", function() {
437                     expect(Ext.valueFrom('bbb', 'aaa', true)).toBe('bbb');
438                 });
439             });
440             
441             describe("and an undefined value", function() {
442                 it("should return the default value", function() {
443                     expect(Ext.valueFrom(undefined, 'aaa', true)).toBe('aaa');
444                 });
445             });
446             
447             describe("and a null value", function() {
448                 it("should return the default value", function() {
449                     expect(Ext.valueFrom(null, 'aaa', true)).toBe('aaa');
450                 });
451             });
452             
453             describe("and a 0 value", function() {
454                 it("should return the value", function() {
455                     expect(Ext.valueFrom(0, 'aaa', true)).toBe(0);
456                 });
457             });
458         });
459         
460         describe("without allowBlank", function() {
461             describe("and an empty string", function() {
462                 it("should return the default value", function() {
463                     expect(Ext.valueFrom('', 'aaa')).toBe('aaa');
464                 });
465             });
466             
467             describe("and a string", function() {
468                 it("should return the value", function() {
469                     expect(Ext.valueFrom('bbb', 'aaa')).toBe('bbb');
470                 });
471             });
472             
473             describe("and an undefined value", function() {
474                 it("should return the default value", function() {
475                     expect(Ext.valueFrom(undefined, 'aaa')).toBe('aaa');
476                 });
477             });
478             
479             describe("and a null value", function() {
480                 it("should return the default value", function() {
481                     expect(Ext.valueFrom(null, 'aaa')).toBe('aaa');
482                 });
483             });
484             
485             describe("and a 0 value", function() {
486                 it("should return the value", function() {
487                     expect(Ext.valueFrom(0, 'aaa')).toBe(0);
488                 });
489             });
490         });
491     });
492     
493     describe("Ext.typeOf", function() {
494         it("should return null", function() {
495             expect(Ext.typeOf(null)).toEqual('null');
496         });
497         it("should return undefined", function() {
498             expect(Ext.typeOf(undefined)).toEqual('undefined');
499         });
500         it("should return undefined", function() {
501             expect(Ext.typeOf(window.someWeirdPropertyThatDoesntExist)).toEqual('undefined');
502         });
503         it("should return string", function() {
504             expect(Ext.typeOf('')).toEqual('string');
505         });
506         it("should return string", function() {
507             expect(Ext.typeOf('something')).toEqual('string');
508         });
509         it("should return string", function() {
510             expect(Ext.typeOf('1.2')).toEqual('string');
511         });
512         it("should return number", function() {
513             expect(Ext.typeOf(1)).toEqual('number');
514         });
515         it("should return number", function() {
516             expect(Ext.typeOf(1.2)).toEqual('number');
517         });
518         it("should return boolean", function() {
519             expect(Ext.typeOf(true)).toEqual('boolean');
520         });
521         it("should return boolean", function() {
522             expect(Ext.typeOf(false)).toEqual('boolean');
523         });
524         it("should return array", function() {
525             expect(Ext.typeOf([1,2,3])).toEqual('array');
526         });
527         it("should return array", function() {
528             expect(Ext.typeOf(new Array(1,2,3))).toEqual('array');
529         });
530         it("should return function 1", function() {
531             expect(Ext.typeOf(function(){})).toEqual('function');
532         });
533         // Don't run this test in IE
534         if (typeof alert === 'function') {
535             it("should return function 2", function() {
536                 expect(Ext.typeOf(prompt)).toEqual('function');
537             });
538         }
539         it("should return function 3", function() {
540             expect(Ext.typeOf(new Function())).toEqual('function');
541         });
542         it("should return regexp 1", function() {
543             expect(Ext.typeOf(/test/)).toEqual('regexp');
544         });
545         it("should return regexp 2", function() {
546             expect(Ext.typeOf(new RegExp('test'))).toEqual('regexp');
547         });
548         it("should return date", function() {
549             expect(Ext.typeOf(new Date())).toEqual('date');
550         });
551         it("should return textnode", function() {
552             expect(Ext.typeOf(document.createTextNode('tada'))).toEqual('textnode');
553         });
554         it("should return whitespace", function() {
555             expect(Ext.typeOf(document.createTextNode(' '))).toEqual('whitespace');
556         });
557         it("should return whitespace", function() {
558             expect(Ext.typeOf(document.createTextNode('         '))).toEqual('whitespace');
559         });
560         it("should return element", function() {
561             expect(Ext.typeOf(document.getElementsByTagName('body')[0])).toEqual('element');
562         });
563         it("should return element", function() {
564             expect(Ext.typeOf(document.createElement('button'))).toEqual('element');
565         });
566         it("should return element", function() {
567             expect(Ext.typeOf(new Image())).toEqual('element');
568         });
569         it("should return object 1", function() {
570             expect(Ext.typeOf({some: 'stuff'})).toEqual('object');
571         });
572         it("should return object 2", function() {
573             expect(Ext.typeOf(new Object())).toEqual('object');
574         });
575         it("should return object 3", function() {
576             expect(Ext.typeOf(window)).toEqual('object');
577         });
578         it("should return boolean", function() {
579             expect(Ext.typeOf(new Boolean(true))).toEqual('boolean');
580         });
581         it("should return number", function() {
582             expect(Ext.typeOf(new Number(1.2))).toEqual('number');
583         });
584     });
585
586     describe("Ext.isIterable", function() {
587         it("should return true with empty array", function() {
588             expect(Ext.isIterable([])).toBe(true);
589         });
590
591         it("should return true with filled array", function() {
592             expect(Ext.isIterable([1, 2, 3, 4])).toBe(true);
593         });
594
595         it("should return false with boolean true", function() {
596             expect(Ext.isIterable(true)).toBe(false);
597         });
598
599         it("should return false with boolean false", function() {
600             expect(Ext.isIterable(false)).toBe(false);
601         });
602
603         it("should return false with string", function() {
604             expect(Ext.isIterable("foo")).toBe(false);
605         });
606
607         it("should return false with empty string", function() {
608             expect(Ext.isIterable("")).toBe(false);
609         });
610
611         it("should return false with number", function() {
612             expect(Ext.isIterable(1)).toBe(false);
613         });
614
615         it("should return false with null", function() {
616             expect(Ext.isIterable(null)).toBe(false);
617         });
618
619         it("should return false with undefined", function() {
620             expect(Ext.isIterable(undefined)).toBe(false);
621         });
622
623         it("should return false with date", function() {
624             expect(Ext.isIterable(new Date())).toBe(false);
625         });
626
627         it("should return false with empty object", function() {
628             expect(Ext.isIterable({})).toBe(false);
629         });
630
631         it("should return true with node list", function() {
632             expect(Ext.isIterable(document.getElementsByTagName('body'))).toBe(true);
633         });
634
635         it("should return true with html collection", function() {
636             expect(Ext.isIterable(document.images)).toBe(true);
637         });
638     });
639
640     describe("Ext.isArray", function() {
641         it("should return true with empty array", function() {
642             expect(Ext.isArray([])).toBe(true);
643         });
644
645         it("should return true with filled array", function() {
646             expect(Ext.isArray([1, 2, 3, 4])).toBe(true);
647         });
648
649         it("should return false with boolean true", function() {
650             expect(Ext.isArray(true)).toBe(false);
651         });
652
653         it("should return false with boolean false", function() {
654             expect(Ext.isArray(false)).toBe(false);
655         });
656
657         it("should return false with string", function() {
658             expect(Ext.isArray("foo")).toBe(false);
659         });
660
661         it("should return false with empty string", function() {
662             expect(Ext.isArray("")).toBe(false);
663         });
664
665         it("should return false with number", function() {
666             expect(Ext.isArray(1)).toBe(false);
667         });
668
669         it("should return false with null", function() {
670             expect(Ext.isArray(null)).toBe(false);
671         });
672
673         it("should return false with undefined", function() {
674             expect(Ext.isArray(undefined)).toBe(false);
675         });
676
677         it("should return false with date", function() {
678             expect(Ext.isArray(new Date())).toBe(false);
679         });
680
681         it("should return false with empty object", function() {
682             expect(Ext.isArray({})).toBe(false);
683         });
684
685         it("should return false with node list", function() {
686             expect(Ext.isArray(document.getElementsByTagName('body'))).toBe(false);
687         });
688
689         it("should return false with custom class that has a length property", function() {
690             var C = Ext.extend(Object, {
691                 length: 1
692             });
693             expect(Ext.isArray(new C())).toBe(false);
694         });
695
696         it("should return false with element", function() {
697            expect(Ext.isArray(Ext.getBody().dom)).toBe(false);
698         });
699     });
700
701     describe("Ext.isBoolean", function() {
702         it("should return false with empty array", function() {
703             expect(Ext.isBoolean([])).toBe(false);
704         });
705
706         it("should return false with filled array", function() {
707             expect(Ext.isBoolean([1, 2, 3, 4])).toBe(false);
708         });
709
710         it("should return true with boolean true", function() {
711             expect(Ext.isBoolean(true)).toBe(true);
712         });
713
714         it("should return true with boolean false", function() {
715             expect(Ext.isBoolean(false)).toBe(true);
716         });
717
718         it("should return false with string", function() {
719             expect(Ext.isBoolean("foo")).toBe(false);
720         });
721
722         it("should return false with empty string", function() {
723             expect(Ext.isBoolean("")).toBe(false);
724         });
725
726         it("should return false with number", function() {
727             expect(Ext.isBoolean(1)).toBe(false);
728         });
729
730         it("should return false with null", function() {
731             expect(Ext.isBoolean(null)).toBe(false);
732         });
733
734         it("should return false with undefined", function() {
735             expect(Ext.isBoolean(undefined)).toBe(false);
736         });
737
738         it("should return false with date", function() {
739             expect(Ext.isBoolean(new Date())).toBe(false);
740         });
741
742         it("should return false with empty object", function() {
743             expect(Ext.isBoolean({})).toBe(false);
744         });
745
746         it("should return false with node list", function() {
747             expect(Ext.isBoolean(document.getElementsByTagName('body'))).toBe(false);
748         });
749
750         it("should return false with element", function() {
751            expect(Ext.isArray(Ext.getBody().dom)).toBe(false);
752         });
753     });
754
755     describe("Ext.isDate", function() {
756         it("should return false with empty array", function() {
757             expect(Ext.isDate([])).toBe(false);
758         });
759
760         it("should return false with filled array", function() {
761             expect(Ext.isDate([1, 2, 3, 4])).toBe(false);
762         });
763
764         it("should return false with boolean true", function() {
765             expect(Ext.isDate(true)).toBe(false);
766         });
767
768         it("should return false with boolean false", function() {
769             expect(Ext.isDate(false)).toBe(false);
770         });
771
772         it("should return false with string", function() {
773             expect(Ext.isDate("foo")).toBe(false);
774         });
775
776         it("should return false with empty string", function() {
777             expect(Ext.isDate("")).toBe(false);
778         });
779
780         it("should return false with number", function() {
781             expect(Ext.isDate(1)).toBe(false);
782         });
783
784         it("should return false with null", function() {
785             expect(Ext.isDate(null)).toBe(false);
786         });
787
788         it("should return false with undefined", function() {
789             expect(Ext.isDate(undefined)).toBe(false);
790         });
791
792         it("should return true with date", function() {
793             expect(Ext.isDate(new Date())).toBe(true);
794         });
795
796         it("should return false with empty object", function() {
797             expect(Ext.isDate({})).toBe(false);
798         });
799
800         it("should return false with node list", function() {
801             expect(Ext.isDate(document.getElementsByTagName('body'))).toBe(false);
802         });
803
804         it("should return false with element", function() {
805             expect(Ext.isDate(Ext.getBody().dom)).toBe(false);
806         });
807     });
808
809     describe("Ext.isDefined", function() {
810         it("should return true with empty array", function() {
811             expect(Ext.isDefined([])).toBe(true);
812         });
813
814         it("should return true with filled array", function() {
815             expect(Ext.isDefined([1, 2, 3, 4])).toBe(true);
816         });
817
818         it("should return true with boolean true", function() {
819             expect(Ext.isDefined(true)).toBe(true);
820         });
821
822         it("should return true with boolean false", function() {
823             expect(Ext.isDefined(false)).toBe(true);
824         });
825
826         it("should return true with string", function() {
827             expect(Ext.isDefined("foo")).toBe(true);
828         });
829
830         it("should return true with empty string", function() {
831             expect(Ext.isDefined("")).toBe(true);
832         });
833
834         it("should return true with number", function() {
835             expect(Ext.isDefined(1)).toBe(true);
836         });
837
838         it("should return true with null", function() {
839             expect(Ext.isDefined(null)).toBe(true);
840         });
841
842         it("should return false with undefined", function() {
843             expect(Ext.isDefined(undefined)).toBe(false);
844         });
845
846         it("should return true with date", function() {
847             expect(Ext.isDefined(new Date())).toBe(true);
848         });
849
850         it("should return true with empty object", function() {
851             expect(Ext.isDefined({})).toBe(true);
852         });
853
854         it("should return true with node list", function() {
855             expect(Ext.isDefined(document.getElementsByTagName('body'))).toBe(true);
856         });
857
858         it("should return true with element", function() {
859            expect(Ext.isDefined(Ext.getBody().dom)).toBe(true);
860         });
861     });
862
863     describe("Ext.isElement", function() {
864         it("should return false with empty array", function() {
865             expect(Ext.isElement([])).toBe(false);
866         });
867
868         it("should return false with filled array", function() {
869             expect(Ext.isElement([1, 2, 3, 4])).toBe(false);
870         });
871
872         it("should return false with boolean true", function() {
873             expect(Ext.isElement(true)).toBe(false);
874         });
875
876         it("should return false with boolean false", function() {
877             expect(Ext.isElement(false)).toBe(false);
878         });
879
880         it("should return false with string", function() {
881             expect(Ext.isElement("foo")).toBe(false);
882         });
883
884         it("should return false with empty string", function() {
885             expect(Ext.isElement("")).toBe(false);
886         });
887
888         it("should return false with number", function() {
889             expect(Ext.isElement(1)).toBe(false);
890         });
891
892         it("should return false with null", function() {
893             expect(Ext.isElement(null)).toBe(false);
894         });
895
896         it("should return false with undefined", function() {
897             expect(Ext.isElement(undefined)).toBe(false);
898         });
899
900         it("should return false with date", function() {
901             expect(Ext.isElement(new Date())).toBe(false);
902         });
903
904         it("should return false with empty object", function() {
905             expect(Ext.isElement({})).toBe(false);
906         });
907
908         it("should return false with node list", function() {
909             expect(Ext.isElement(document.getElementsByTagName('body'))).toBe(false);
910         });
911
912         it("should return true with element", function() {
913            expect(Ext.isElement(Ext.getBody().dom)).toBe(true);
914         });
915
916         it("should return false with Ext.core.Element", function() {
917            expect(Ext.isElement(Ext.getBody())).toBe(false);
918         });
919         
920         it("should return false with TextNode", function() {
921             var textNode = document.createTextNode('foobar');
922             document.body.appendChild(textNode);
923             expect(Ext.isElement(textNode)).toBe(false);
924             document.body.removeChild(textNode);
925         });
926     });
927
928     describe("Ext.isEmpty", function() {
929         it("should return true with empty array", function() {
930             expect(Ext.isEmpty([])).toBe(true);
931         });
932
933         it("should return false with filled array", function() {
934             expect(Ext.isEmpty([1, 2, 3, 4])).toBe(false);
935         });
936
937         it("should return false with boolean true", function() {
938             expect(Ext.isEmpty(true)).toBe(false);
939         });
940
941         it("should return false with boolean false", function() {
942             expect(Ext.isEmpty(false)).toBe(false);
943         });
944
945         it("should return false with string", function() {
946             expect(Ext.isEmpty("foo")).toBe(false);
947         });
948
949         it("should return true with empty string", function() {
950             expect(Ext.isEmpty("")).toBe(true);
951         });
952
953         it("should return true with empty string with allowBlank", function() {
954             expect(Ext.isEmpty("", true)).toBe(false);
955         });
956
957         it("should return false with number", function() {
958             expect(Ext.isEmpty(1)).toBe(false);
959         });
960
961         it("should return true with null", function() {
962             expect(Ext.isEmpty(null)).toBe(true);
963         });
964
965         it("should return true with undefined", function() {
966             expect(Ext.isEmpty(undefined)).toBe(true);
967         });
968
969         it("should return false with date", function() {
970             expect(Ext.isEmpty(new Date())).toBe(false);
971         });
972
973         it("should return false with empty object", function() {
974             expect(Ext.isEmpty({})).toBe(false);
975         });
976     });
977
978     describe("Ext.isFunction", function() {
979         beforeEach(function() {
980             // add global variable in whitelist
981             addGlobal("ExtSandbox1");
982         });
983
984         it("should return true with anonymous function", function() {
985             expect(Ext.isFunction(function(){})).toBe(true);
986         });
987
988         it("should return true with new Function syntax", function() {
989             expect(Ext.isFunction(Ext.functionFactory('return "";'))).toBe(true);
990         });
991
992         it("should return true with static function", function() {
993             expect(Ext.isFunction(Ext.emptyFn)).toBe(true);
994         });
995
996         it("should return true with instance function", function() {
997             var stupidClass = function() {},
998                 testObject;
999             stupidClass.prototype.testMe = function() {};
1000             testObject = new stupidClass();
1001
1002             expect(Ext.isFunction(testObject.testMe)).toBe(true);
1003         });
1004
1005         it("should return true with function on object", function() {
1006             var o = {
1007                 fn: function() {
1008                 }
1009             };
1010
1011             expect(Ext.isFunction(o.fn)).toBe(true);
1012         });
1013
1014         it("should return false with empty array", function() {
1015             expect(Ext.isFunction([])).toBe(false);
1016         });
1017
1018         it("should return false with filled array", function() {
1019             expect(Ext.isFunction([1, 2, 3, 4])).toBe(false);
1020         });
1021
1022         it("should return false with boolean true", function() {
1023             expect(Ext.isFunction(true)).toBe(false);
1024         });
1025
1026         it("should return false with boolean false", function() {
1027             expect(Ext.isFunction(false)).toBe(false);
1028         });
1029
1030         it("should return false with string", function() {
1031             expect(Ext.isFunction("foo")).toBe(false);
1032         });
1033
1034         it("should return false with empty string", function() {
1035             expect(Ext.isFunction("")).toBe(false);
1036         });
1037
1038         it("should return false with number", function() {
1039             expect(Ext.isFunction(1)).toBe(false);
1040         });
1041
1042         it("should return false with null", function() {
1043             expect(Ext.isFunction(null)).toBe(false);
1044         });
1045
1046         it("should return false with undefined", function() {
1047             expect(Ext.isFunction(undefined)).toBe(false);
1048         });
1049
1050         it("should return false with date", function() {
1051             expect(Ext.isFunction(new Date())).toBe(false);
1052         });
1053
1054         it("should return false with empty object", function() {
1055             expect(Ext.isFunction({})).toBe(false);
1056         });
1057
1058         it("should return false with node list", function() {
1059             expect(Ext.isFunction(document.getElementsByTagName('body'))).toBe(false);
1060         });
1061     });
1062
1063     describe("Ext.isNumber", function() {
1064         it("should return true with zero", function() {
1065             expect(Ext.isNumber(0)).toBe(true);
1066         });
1067
1068         it("should return true with non zero", function() {
1069             expect(Ext.isNumber(4)).toBe(true);
1070         });
1071
1072         it("should return true with negative integer", function() {
1073             expect(Ext.isNumber(-3)).toBe(true);
1074         });
1075
1076         it("should return true with float", function() {
1077             expect(Ext.isNumber(1.75)).toBe(true);
1078         });
1079
1080         it("should return true with negative float", function() {
1081             expect(Ext.isNumber(-4.75)).toBe(true);
1082         });
1083
1084         it("should return true with Number.MAX_VALUE", function() {
1085             expect(Ext.isNumber(Number.MAX_VALUE)).toBe(true);
1086         });
1087
1088         it("should return true with Number.MIN_VALUE", function() {
1089             expect(Ext.isNumber(Number.MIN_VALUE)).toBe(true);
1090         });
1091
1092         it("should return true with Math.PI", function() {
1093             expect(Ext.isNumber(Math.PI)).toBe(true);
1094         });
1095
1096         it("should return true with Number() contructor", function() {
1097             expect(Ext.isNumber(Number('3.1'))).toBe(true);
1098         });
1099
1100         it("should return false with NaN", function() {
1101             expect(Ext.isNumber(Number.NaN)).toBe(false);
1102         });
1103
1104         it("should return false with Number.POSITIVE_INFINITY", function() {
1105             expect(Ext.isNumber(Number.POSITIVE_INFINITY)).toBe(false);
1106         });
1107
1108         it("should return false with Number.NEGATIVE_INFINITY", function() {
1109             expect(Ext.isNumber(Number.NEGATIVE_INFINITY)).toBe(false);
1110         });
1111
1112         it("should return false with empty array", function() {
1113             expect(Ext.isNumber([])).toBe(false);
1114         });
1115
1116         it("should return false with filled array", function() {
1117             expect(Ext.isNumber([1, 2, 3, 4])).toBe(false);
1118         });
1119
1120         it("should return false with boolean true", function() {
1121             expect(Ext.isNumber(true)).toBe(false);
1122         });
1123
1124         it("should return false with boolean false", function() {
1125             expect(Ext.isNumber(false)).toBe(false);
1126         });
1127
1128         it("should return false with string", function() {
1129             expect(Ext.isNumber("foo")).toBe(false);
1130         });
1131
1132         it("should return false with empty string", function() {
1133             expect(Ext.isNumber("")).toBe(false);
1134         });
1135
1136         it("should return false with string containing a number", function() {
1137             expect(Ext.isNumber("1.0")).toBe(false);
1138         });
1139
1140         it("should return false with undefined", function() {
1141             expect(Ext.isNumber(undefined)).toBe(false);
1142         });
1143
1144         it("should return false with date", function() {
1145             expect(Ext.isNumber(new Date())).toBe(false);
1146         });
1147
1148         it("should return false with empty object", function() {
1149             expect(Ext.isNumber({})).toBe(false);
1150         });
1151
1152         it("should return false with node list", function() {
1153             expect(Ext.isNumber(document.getElementsByTagName('body'))).toBe(false);
1154         });
1155     });
1156
1157     describe("Ext.isNumeric", function() {
1158         it("should return true with zero", function() {
1159             expect(Ext.isNumeric(0)).toBe(true);
1160         });
1161
1162         it("should return true with non zero", function() {
1163             expect(Ext.isNumeric(4)).toBe(true);
1164         });
1165
1166         it("should return true with negative integer", function() {
1167             expect(Ext.isNumeric(-3)).toBe(true);
1168         });
1169
1170         it("should return true with float", function() {
1171             expect(Ext.isNumeric(1.75)).toBe(true);
1172         });
1173
1174         it("should return true with negative float", function() {
1175             expect(Ext.isNumeric(-4.75)).toBe(true);
1176         });
1177
1178         it("should return true with Number.MAX_VALUE", function() {
1179             expect(Ext.isNumeric(Number.MAX_VALUE)).toBe(true);
1180         });
1181
1182         it("should return true with Number.MIN_VALUE", function() {
1183             expect(Ext.isNumeric(Number.MIN_VALUE)).toBe(true);
1184         });
1185
1186         it("should return true with Math.PI", function() {
1187             expect(Ext.isNumeric(Math.PI)).toBe(true);
1188         });
1189
1190         it("should return true with Number() contructor", function() {
1191             expect(Ext.isNumeric(Number('3.1'))).toBe(true);
1192         });
1193
1194         it("should return false with NaN", function() {
1195             expect(Ext.isNumeric(Number.NaN)).toBe(false);
1196         });
1197
1198         it("should return false with Number.POSITIVE_INFINITY", function() {
1199             expect(Ext.isNumeric(Number.POSITIVE_INFINITY)).toBe(false);
1200         });
1201
1202         it("should return false with Number.NEGATIVE_INFINITY", function() {
1203             expect(Ext.isNumeric(Number.NEGATIVE_INFINITY)).toBe(false);
1204         });
1205
1206         it("should return false with empty array", function() {
1207             expect(Ext.isNumeric([])).toBe(false);
1208         });
1209
1210         it("should return false with filled array", function() {
1211             expect(Ext.isNumeric([1, 2, 3, 4])).toBe(false);
1212         });
1213
1214         it("should return false with boolean true", function() {
1215             expect(Ext.isNumeric(true)).toBe(false);
1216         });
1217
1218         it("should return false with boolean false", function() {
1219             expect(Ext.isNumeric(false)).toBe(false);
1220         });
1221
1222         it("should return false with string", function() {
1223             expect(Ext.isNumeric("foo")).toBe(false);
1224         });
1225
1226         it("should return false with empty string", function() {
1227             expect(Ext.isNumeric("")).toBe(false);
1228         });
1229
1230         it("should return true with string containing a number", function() {
1231             expect(Ext.isNumeric("1.0")).toBe(true);
1232         });
1233
1234         it("should return false with undefined", function() {
1235             expect(Ext.isNumeric(undefined)).toBe(false);
1236         });
1237
1238         it("should return false with date", function() {
1239             expect(Ext.isNumeric(new Date())).toBe(false);
1240         });
1241
1242         it("should return false with empty object", function() {
1243             expect(Ext.isNumeric({})).toBe(false);
1244         });
1245
1246         it("should return false with node list", function() {
1247             expect(Ext.isNumeric(document.getElementsByTagName('body'))).toBe(false);
1248         });
1249     });
1250     
1251     describe("Ext.isObject", function() {
1252         it("should return false with empty array", function() {
1253             expect(Ext.isObject([])).toBe(false);
1254         });
1255
1256         it("should return false with filled array", function() {
1257             expect(Ext.isObject([1, 2, 3, 4])).toBe(false);
1258         });
1259
1260         it("should return false with boolean true", function() {
1261             expect(Ext.isObject(true)).toBe(false);
1262         });
1263
1264         it("should return false with boolean false", function() {
1265             expect(Ext.isObject(false)).toBe(false);
1266         });
1267
1268         it("should return false with string", function() {
1269             expect(Ext.isObject("foo")).toBe(false);
1270         });
1271
1272         it("should return false with empty string", function() {
1273             expect(Ext.isObject("")).toBe(false);
1274         });
1275
1276         it("should return false with number", function() {
1277             expect(Ext.isObject(1)).toBe(false);
1278         });
1279
1280         it("should return false with null", function() {
1281             expect(Ext.isObject(null)).toBe(false);
1282         });
1283
1284         it("should return false with undefined", function() {
1285             expect(Ext.isObject(undefined)).toBe(false);
1286         });
1287
1288         it("should return false with date", function() {
1289             expect(Ext.isObject(new Date())).toBe(false);
1290         });
1291
1292         it("should return true with empty object", function() {
1293             expect(Ext.isObject({})).toBe(true);
1294         });
1295
1296         it("should return false with a DOM node", function() {
1297             expect(Ext.isObject(document.body)).toBe(false);
1298         });
1299
1300         it("should return false with a Text node", function() {
1301             expect(Ext.isObject(document.createTextNode('test'))).toBe(false);
1302         });
1303
1304         it("should return true with object with properties", function() {
1305             expect(Ext.isObject({
1306                 foo: 1
1307             })).toBe(true);
1308         });
1309
1310         it("should return true with object instance", function() {
1311             var stupidClass = function() {};
1312
1313             expect(Ext.isObject(new stupidClass())).toBe(true);
1314         });
1315
1316         it("should return true with new Object syntax", function() {
1317             expect(Ext.isObject(new Object())).toBe(true);
1318         });
1319
1320         it("should return false with dom element", function() {
1321             expect(Ext.isObject(document.body)).toBe(false);
1322         });
1323     });
1324
1325     describe("Ext.isPrimitive", function() {
1326         it("should return true with integer", function() {
1327             expect(Ext.isPrimitive(1)).toBe(true);
1328         });
1329
1330         it("should return true with negative integer", function() {
1331             expect(Ext.isPrimitive(-21)).toBe(true);
1332         });
1333
1334         it("should return true with float", function() {
1335             expect(Ext.isPrimitive(2.1)).toBe(true);
1336         });
1337
1338         it("should return true with negative float", function() {
1339             expect(Ext.isPrimitive(-12.1)).toBe(true);
1340         });
1341
1342         it("should return true with Number.MAX_VALUE", function() {
1343             expect(Ext.isPrimitive(Number.MAX_VALUE)).toBe(true);
1344         });
1345
1346         it("should return true with Math.PI", function() {
1347             expect(Ext.isPrimitive(Math.PI)).toBe(true);
1348         });
1349
1350         it("should return true with empty string", function() {
1351             expect(Ext.isPrimitive("")).toBe(true);
1352         });
1353
1354         it("should return true with non empty string", function() {
1355             expect(Ext.isPrimitive("foo")).toBe(true);
1356         });
1357
1358         it("should return true with boolean true", function() {
1359             expect(Ext.isPrimitive(true)).toBe(true);
1360         });
1361
1362         it("should return true with boolean false", function() {
1363             expect(Ext.isPrimitive(false)).toBe(true);
1364         });
1365
1366         it("should return false with null", function() {
1367             expect(Ext.isPrimitive(null)).toBe(false);
1368         });
1369
1370         it("should return false with undefined", function() {
1371             expect(Ext.isPrimitive(undefined)).toBe(false);
1372         });
1373
1374         it("should return false with object", function() {
1375             expect(Ext.isPrimitive({})).toBe(false);
1376         });
1377
1378         it("should return false with object instance", function() {
1379             var stupidClass = function() {};
1380             expect(Ext.isPrimitive(new stupidClass())).toBe(false);
1381         });
1382
1383         it("should return false with array", function() {
1384             expect(Ext.isPrimitive([])).toBe(false);
1385         });
1386     });
1387
1388     describe("Ext.isString", function() {
1389         it("should return true with empty string", function() {
1390             expect(Ext.isString("")).toBe(true);
1391         });
1392
1393         it("should return true with non empty string", function() {
1394             expect(Ext.isString("foo")).toBe(true);
1395         });
1396
1397         it("should return true with String() syntax", function() {
1398             expect(Ext.isString(String(""))).toBe(true);
1399         });
1400
1401         it("should return false with new String() syntax", function() { //should return an object that wraps the primitive
1402             expect(Ext.isString(new String(""))).toBe(false);
1403         });
1404
1405         it("should return false with number", function() {
1406             expect(Ext.isString(1)).toBe(false);
1407         });
1408
1409         it("should return false with boolean", function() {
1410             expect(Ext.isString(true)).toBe(false);
1411         });
1412
1413         it("should return false with null", function() {
1414             expect(Ext.isString(null)).toBe(false);
1415         });
1416
1417         it("should return false with undefined", function() {
1418             expect(Ext.isString(undefined)).toBe(false);
1419         });
1420
1421         it("should return false with array", function() {
1422             expect(Ext.isString([])).toBe(false);
1423         });
1424
1425         it("should return false with object", function() {
1426             expect(Ext.isString({})).toBe(false);
1427         });
1428     });
1429
1430     describe("Ext.isTextNode", function() {
1431         it("should return false with empty array", function() {
1432             expect(Ext.isTextNode([])).toBe(false);
1433         });
1434
1435         it("should return false with filled array", function() {
1436             expect(Ext.isTextNode([1, 2, 3, 4])).toBe(false);
1437         });
1438
1439         it("should return false with boolean true", function() {
1440             expect(Ext.isTextNode(true)).toBe(false);
1441         });
1442
1443         it("should return false with boolean false", function() {
1444             expect(Ext.isTextNode(false)).toBe(false);
1445         });
1446
1447         it("should return false with string", function() {
1448             expect(Ext.isTextNode("foo")).toBe(false);
1449         });
1450
1451         it("should return false with empty string", function() {
1452             expect(Ext.isTextNode("")).toBe(false);
1453         });
1454
1455         it("should return false with number", function() {
1456             expect(Ext.isTextNode(1)).toBe(false);
1457         });
1458
1459         it("should return false with null", function() {
1460             expect(Ext.isTextNode(null)).toBe(false);
1461         });
1462
1463         it("should return false with undefined", function() {
1464             expect(Ext.isTextNode(undefined)).toBe(false);
1465         });
1466
1467         it("should return false with date", function() {
1468             expect(Ext.isTextNode(new Date())).toBe(false);
1469         });
1470
1471         it("should return false with empty object", function() {
1472             expect(Ext.isTextNode({})).toBe(false);
1473         });
1474
1475         it("should return false with node list", function() {
1476             expect(Ext.isTextNode(document.getElementsByTagName('body'))).toBe(false);
1477         }); 
1478         
1479         it("should return false with element", function() {
1480            expect(Ext.isTextNode(Ext.getBody().dom)).toBe(false);
1481         });
1482
1483         it("should return false with Ext.core.Element", function() {
1484            expect(Ext.isTextNode(Ext.getBody())).toBe(false);
1485         });
1486         
1487         it("should return true with TextNode", function() {
1488             var textNode = document.createTextNode('foobar');
1489             document.body.appendChild(textNode);
1490             expect(Ext.isTextNode(textNode)).toBe(true);
1491             document.body.removeChild(textNode);
1492         });    
1493     });
1494     
1495     describe("Ext.clone", function() {
1496         var clone;
1497         
1498         afterEach(function() {
1499             clone = null;
1500         });
1501         
1502         it("should clone an array", function() {
1503             var array = [2,'5',[1,3,4]];
1504             clone = Ext.clone(array);
1505             expect(clone).toEqual(array);
1506             expect(clone).not.toBe(array);
1507         });
1508         
1509         it("should clone an object", function() {
1510             var object = {
1511                 fn: function() {
1512                     return 1;
1513                 },
1514                 b: 2
1515             };
1516             clone = Ext.clone(object);
1517             expect(clone).toEqual(object);
1518             expect(clone).not.toBe(object);
1519         });
1520         
1521         it("should clone a date", function(){
1522             var date = new Date(); 
1523             clone = Ext.clone(date);
1524             expect(clone).toEqual(date);
1525             expect(clone).not.toBe(date);
1526         });
1527         
1528         it("should clone a dom node", function(){
1529             var node = document.createElement('DIV');
1530             document.body.appendChild(node); 
1531             clone = Ext.clone(node);
1532             expect(clone.tagName).toEqual(clone.tagName);
1533             expect(clone.innerHTML).toEqual(clone.innerHTML);
1534             expect(clone).not.toBe(node);
1535             document.body.removeChild(node);
1536         });
1537     });
1538     
1539     describe('getUniqueGlobalNamespace', function() {
1540         it("should return an unique global namespace", function() {
1541             expect(Ext.getUniqueGlobalNamespace()).toBe("ExtSandbox1"); 
1542         });
1543     });
1544 });