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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
describe('fiveui.Messenger', function() {
var chan1 = null;
var chan2 = null;
var m1 = null;
var m2 = null;
beforeEach(function() {
chan1 = new fiveui.Chan();
chan2 = new fiveui.Chan();
chan2.chan = chan1;
chan1.chan = chan2
m1 = new fiveui.Messenger(chan1);
m2 = new fiveui.Messenger(chan2);
});
afterEach(function() {
delete m1;
delete chan1;
delete m2;
delete chan2;
});
it('registers a simple callback', function() {
var got = [];
m1.register('count', function(n) {
got.push(n);
});
m2.send('count', 1);
m2.send('count', 2);
expect(got).toEqual([1,2]);
});
it('supports respond callbacks when sending', function() {
var m1got = [];
var m2got = [];
m1.register('count', function(n, respond){
m1got.push(n);
respond(n);
});
m2.send('count', 1, function(n) {
m2got.push(n);
});
expect(m1got.length).toBe(m2got.length);
});
it('doesn\'t invoke callbacks for null data', function() {
var m1got = [];
m1.register('count', function(n) {
m1got.push(n);
});
m2.send('count', null);
expect(m1got[0]).toBe(null);
});
it('is able to send rules', function() {
var ruleIn = new fiveui.Rule(42, 'testRule',
'see: http://test.description/',
'function() { console.log("fail"); }');
var got = [];
m1.register('rule', function(r){
got.push(r);
});
m2.send('rule', ruleIn);
expect(got.length).toBe(1);
var ruleOut = got[0];
expect(ruleIn.id).toBe(ruleOut.id);
expect(ruleIn.name).toBe(ruleOut.name);
expect(ruleIn.description).toBe(ruleOut.description);
expect(ruleIn.ruleStr).toBe(ruleOut.ruleStr);
});
});
|