Script and makefile adjustments for updating extlib
[larjonas-mediagoblin.git] / extlib / leaflet / spec / suites / core / ClassSpec.js
blob7a289154b85f77fc3aead4f5c1eb3276a61c7394
1 describe("Class", function() {
3 describe("#extend", function() {
4 var Klass,
5 constructor,
6 method;
8 beforeEach(function() {
9 constructor = jasmine.createSpy(),
10 method = jasmine.createSpy();
12 Klass = L.Class.extend({
13 statics: {bla: 1},
14 includes: {mixin: true},
16 initialize: constructor,
17 foo: 5,
18 bar: method
19 });
20 });
22 it("should create a class with the given constructor & properties", function() {
23 var a = new Klass();
25 expect(constructor).toHaveBeenCalled();
26 expect(a.foo).toEqual(5);
28 a.bar();
30 expect(method).toHaveBeenCalled();
31 });
33 it("should inherit parent classes' constructor & properties", function() {
34 var Klass2 = Klass.extend({baz: 2});
36 var b = new Klass2();
38 expect(b instanceof Klass).toBeTruthy();
39 expect(b instanceof Klass2).toBeTruthy();
41 expect(constructor).toHaveBeenCalled();
42 expect(b.baz).toEqual(2);
44 b.bar();
46 expect(method).toHaveBeenCalled();
47 });
49 it("should grant the ability to call parent methods, including constructor", function() {
50 var Klass2 = Klass.extend({
51 initialize: function() {},
52 bar: function() {}
53 });
55 var b = new Klass2();
57 expect(constructor).not.toHaveBeenCalled();
58 b.superclass.initialize.call(this);
59 expect(constructor).toHaveBeenCalled();
61 b.superclass.bar.call(this);
62 expect(method).toHaveBeenCalled();
63 });
65 it("should support static properties", function() {
66 expect(Klass.bla).toEqual(1);
67 });
69 it("should inherit parent static properties", function() {
70 var Klass2 = Klass.extend({});
72 expect(Klass2.bla).toEqual(1);
73 });
75 it("should include the given mixin", function() {
76 var a = new Klass();
77 expect(a.mixin).toBeTruthy();
78 });
80 it("should be able to include multiple mixins", function() {
81 var Klass2 = L.Class.extend({
82 includes: [{mixin: true}, {mixin2: true}]
83 });
84 var a = new Klass2();
86 expect(a.mixin).toBeTruthy();
87 expect(a.mixin2).toBeTruthy();
88 });
90 it("should grant the ability to include the given mixin", function() {
91 Klass.include({mixin2: true});
93 var a = new Klass();
94 expect(a.mixin2).toBeTruthy();
95 });
97 it("should merge options instead of replacing them", function() {
98 var KlassWithOptions1 = L.Class.extend({
99 options: {
100 foo1: 1,
101 foo2: 2
104 var KlassWithOptions2 = KlassWithOptions1.extend({
105 options: {
106 foo2: 3,
107 foo3: 4
111 var a = new KlassWithOptions2();
113 expect(a.options).toEqual({
114 foo1: 1,
115 foo2: 3,
116 foo3: 4