UNPKG

2.67 kBJavaScriptView Raw
1var boo = require('../src/boo')
2
3describe('Module: boo', function() {
4
5 describe('extend', function() {
6 it('- Should modify the first argument', function() {
7 var x = {}
8 boo.extend(x, {a: 1})
9 x.a.should.equal(1) })
10
11 it('- Should use right-most precedence', function() {
12 var x = {a:1}
13 boo.extend(x, {b:1}, {a:2}, {c:3, b:3})
14 x.a.should.equal(2)
15 x.b.should.equal(3)
16 x.c.should.equal(3) })
17
18 it('- Should clone mixins using the #to_data method', function() {
19 var x = {}
20 var y = {data:[], to_data:function(){ return { data:[] }}}
21 boo.extend(x, y)
22 x.data.push(1)
23 y.data.should.be.empty
24 x.data.length.should.equal(1)
25 x.data[0].should.equal(1) })
26 })
27
28 describe('merge', function() {
29 it('- Should return merge all mixins in one object', function() {
30 var x = {a: 1}
31 var y = {b: 2}
32 var z = {a: 3}
33 var a = boo.merge(x, y, z)
34 a.a.should.equal(3)
35 a.b.should.equal(2)
36 })
37 it('- Should not modify any mixins', function() {
38 var x = {a: 1}
39 var y = {b: 2}
40 var z = {a: 3}
41 var a = boo.merge(x, y, z)
42 x.a.should.equal(1)
43 y.b.should.equal(2)
44 z.a.should.equal(3)
45 })
46 })
47
48 describe('derive', function() {
49 it('- Should make a new object inheriting from proto', function() {
50 var foo = {a:1}
51 var bar = boo.derive(foo, {a:2})
52 bar.a.should.equal(2)
53 foo.isPrototypeOf(bar).should.be.true })
54
55 it('- Should extend the new object with the given mixins', function() {
56 var foo = {a:1}
57 var bar = boo.derive(foo, {b:2, c:3, a:4})
58 foo.should.not.have.property('b')
59 foo.should.not.have.property('c')
60 foo.a.should.equal(1)
61 bar.a.should.equal(4)
62 bar.b.should.equal(2)
63 bar.c.should.equal(3) })
64 })
65
66 describe('Object: Base', function() {
67 describe('make', function() {
68 it('- Should clone `this`', function() {
69 var x = boo.Base.make()
70 boo.Base.isPrototypeOf(x).should.be.true })
71
72 it('- Should apply the `init` method, if present', function(){
73 var y = boo.Base.derive({init:function(n){ this.a = n }})
74 var z = y.make(3)
75 z.a.should.equal(3) })
76 })
77
78 describe('derive', function() {
79 it('- Should derive from `this`', function(){
80 var bar = boo.Base.derive({a:2})
81 boo.Base.isPrototypeOf(bar).should.be.true })
82
83 it('- Should extend the new object with the gven mixins', function() {
84 var bar = boo.Base.derive({a:2}, {b:3}, {c:4})
85 bar.a.should.equal(2)
86 bar.b.should.equal(3)
87 bar.c.should.equal(4) })
88 })
89 })
90})
\No newline at end of file