Installed leaflet in extlib
[mediagoblin.git] / extlib / leaflet / spec / suites / core / ClassSpec.js
CommitLineData
c5ba5b04
JW
1describe("Class", function() {\r
2 \r
3 describe("#extend", function() {\r
4 var Klass,\r
5 constructor,\r
6 method;\r
7 \r
8 beforeEach(function() {\r
9 constructor = jasmine.createSpy(),\r
10 method = jasmine.createSpy();\r
11\r
12 Klass = L.Class.extend({\r
13 statics: {bla: 1},\r
14 includes: {mixin: true},\r
15 \r
16 initialize: constructor,\r
17 foo: 5,\r
18 bar: method\r
19 });\r
20 });\r
21 \r
22 it("should create a class with the given constructor & properties", function() {\r
23 var a = new Klass();\r
24 \r
25 expect(constructor).toHaveBeenCalled();\r
26 expect(a.foo).toEqual(5);\r
27 \r
28 a.bar();\r
29 \r
30 expect(method).toHaveBeenCalled();\r
31 });\r
32 \r
33 it("should inherit parent classes' constructor & properties", function() {\r
34 var Klass2 = Klass.extend({baz: 2});\r
35 \r
36 var b = new Klass2();\r
37 \r
38 expect(b instanceof Klass).toBeTruthy();\r
39 expect(b instanceof Klass2).toBeTruthy();\r
40 \r
41 expect(constructor).toHaveBeenCalled();\r
42 expect(b.baz).toEqual(2);\r
43 \r
44 b.bar();\r
45 \r
46 expect(method).toHaveBeenCalled();\r
47 });\r
48 \r
49 it("should grant the ability to call parent methods, including constructor", function() {\r
50 var Klass2 = Klass.extend({\r
51 initialize: function() {},\r
52 bar: function() {}\r
53 });\r
54 \r
55 var b = new Klass2();\r
56 \r
57 expect(constructor).not.toHaveBeenCalled();\r
58 b.superclass.initialize.call(this);\r
59 expect(constructor).toHaveBeenCalled();\r
60\r
61 b.superclass.bar.call(this);\r
62 expect(method).toHaveBeenCalled();\r
63 });\r
64 \r
65 it("should support static properties", function() {\r
66 expect(Klass.bla).toEqual(1);\r
67 });\r
68 \r
69 it("should inherit parent static properties", function() {\r
70 var Klass2 = Klass.extend({});\r
71 \r
72 expect(Klass2.bla).toEqual(1);\r
73 });\r
74 \r
75 it("should include the given mixin", function() {\r
76 var a = new Klass();\r
77 expect(a.mixin).toBeTruthy();\r
78 });\r
79 \r
80 it("should be able to include multiple mixins", function() {\r
81 var Klass2 = L.Class.extend({\r
82 includes: [{mixin: true}, {mixin2: true}]\r
83 });\r
84 var a = new Klass2();\r
85 \r
86 expect(a.mixin).toBeTruthy();\r
87 expect(a.mixin2).toBeTruthy();\r
88 });\r
89 \r
90 it("should grant the ability to include the given mixin", function() {\r
91 Klass.include({mixin2: true});\r
92 \r
93 var a = new Klass();\r
94 expect(a.mixin2).toBeTruthy();\r
95 });\r
96 \r
97 it("should merge options instead of replacing them", function() {\r
98 var KlassWithOptions1 = L.Class.extend({\r
99 options: {\r
100 foo1: 1,\r
101 foo2: 2\r
102 }\r
103 });\r
104 var KlassWithOptions2 = KlassWithOptions1.extend({\r
105 options: {\r
106 foo2: 3,\r
107 foo3: 4\r
108 }\r
109 });\r
110 \r
111 var a = new KlassWithOptions2();\r
112 \r
113 expect(a.options).toEqual({\r
114 foo1: 1,\r
115 foo2: 3,\r
116 foo3: 4\r
117 });\r
118 });\r
119 });\r
120});