--- /dev/null
+describe("Class", function() {\r
+ \r
+ describe("#extend", function() {\r
+ var Klass,\r
+ constructor,\r
+ method;\r
+ \r
+ beforeEach(function() {\r
+ constructor = jasmine.createSpy(),\r
+ method = jasmine.createSpy();\r
+\r
+ Klass = L.Class.extend({\r
+ statics: {bla: 1},\r
+ includes: {mixin: true},\r
+ \r
+ initialize: constructor,\r
+ foo: 5,\r
+ bar: method\r
+ });\r
+ });\r
+ \r
+ it("should create a class with the given constructor & properties", function() {\r
+ var a = new Klass();\r
+ \r
+ expect(constructor).toHaveBeenCalled();\r
+ expect(a.foo).toEqual(5);\r
+ \r
+ a.bar();\r
+ \r
+ expect(method).toHaveBeenCalled();\r
+ });\r
+ \r
+ it("should inherit parent classes' constructor & properties", function() {\r
+ var Klass2 = Klass.extend({baz: 2});\r
+ \r
+ var b = new Klass2();\r
+ \r
+ expect(b instanceof Klass).toBeTruthy();\r
+ expect(b instanceof Klass2).toBeTruthy();\r
+ \r
+ expect(constructor).toHaveBeenCalled();\r
+ expect(b.baz).toEqual(2);\r
+ \r
+ b.bar();\r
+ \r
+ expect(method).toHaveBeenCalled();\r
+ });\r
+ \r
+ it("should grant the ability to call parent methods, including constructor", function() {\r
+ var Klass2 = Klass.extend({\r
+ initialize: function() {},\r
+ bar: function() {}\r
+ });\r
+ \r
+ var b = new Klass2();\r
+ \r
+ expect(constructor).not.toHaveBeenCalled();\r
+ b.superclass.initialize.call(this);\r
+ expect(constructor).toHaveBeenCalled();\r
+\r
+ b.superclass.bar.call(this);\r
+ expect(method).toHaveBeenCalled();\r
+ });\r
+ \r
+ it("should support static properties", function() {\r
+ expect(Klass.bla).toEqual(1);\r
+ });\r
+ \r
+ it("should inherit parent static properties", function() {\r
+ var Klass2 = Klass.extend({});\r
+ \r
+ expect(Klass2.bla).toEqual(1);\r
+ });\r
+ \r
+ it("should include the given mixin", function() {\r
+ var a = new Klass();\r
+ expect(a.mixin).toBeTruthy();\r
+ });\r
+ \r
+ it("should be able to include multiple mixins", function() {\r
+ var Klass2 = L.Class.extend({\r
+ includes: [{mixin: true}, {mixin2: true}]\r
+ });\r
+ var a = new Klass2();\r
+ \r
+ expect(a.mixin).toBeTruthy();\r
+ expect(a.mixin2).toBeTruthy();\r
+ });\r
+ \r
+ it("should grant the ability to include the given mixin", function() {\r
+ Klass.include({mixin2: true});\r
+ \r
+ var a = new Klass();\r
+ expect(a.mixin2).toBeTruthy();\r
+ });\r
+ \r
+ it("should merge options instead of replacing them", function() {\r
+ var KlassWithOptions1 = L.Class.extend({\r
+ options: {\r
+ foo1: 1,\r
+ foo2: 2\r
+ }\r
+ });\r
+ var KlassWithOptions2 = KlassWithOptions1.extend({\r
+ options: {\r
+ foo2: 3,\r
+ foo3: 4\r
+ }\r
+ });\r
+ \r
+ var a = new KlassWithOptions2();\r
+ \r
+ expect(a.options).toEqual({\r
+ foo1: 1,\r
+ foo2: 3,\r
+ foo3: 4\r
+ });\r
+ });\r
+ });\r
+});
\ No newline at end of file