Repository navigation
Expand file tree
/
Copy pathclass.js
More file actions
71 lines (54 loc) · 1.65 KB
/
Copy pathclass.js
File metadata and controls
71 lines (54 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
describe("Class", function(){
var User;
beforeEach(function(){
User = Spine.Class.create();
});
it("is sane", function(){
expect(Spine).toBeTruthy();
});
it("can create subclasses", function(){
User.extend({classProperty: true});
var Friend = User.create();
expect(Friend).toBeTruthy();
expect(Friend.classProperty).toBeTruthy();
});
it("can create instance", function(){
User.include({instanceProperty: true});
var Bob = new User();
expect(Bob).toBeTruthy();
expect(Bob.instanceProperty).toBeTruthy();
});
it("should be extendable", function(){
User.extend({classProperty: true});
expect(User.classProperty).toBeTruthy();
});
it("should be includable", function(){
User.include({instanceProperty: true});
expect(User.prototype.instanceProperty).toBeTruthy();
expect((new User()).instanceProperty).toBeTruthy();
});
it("should trigger module callbacks", function(){
var module = {
included: function(){},
extended: function(){}
};
spyOn(module, "included");
User.include(module);
expect(module.included).toHaveBeenCalled();
spyOn(module, "extended");
User.extend(module);
expect(module.extended).toHaveBeenCalled();
});
it("include/extend should raise without arguments", function(){
expect(function(){ User.include(); }).toThrow();
expect(function(){ User.extend(); }).toThrow();
});
it("can proxy functions in class/instance context", function(){
var func = function(){
return this;
};
expect(User.proxy(func)()).toBe(User);
var user = new User();
expect(user.proxy(func)()).toBe(user);
});
});