-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathtest.channel.js
79 lines (65 loc) · 2.4 KB
/
test.channel.js
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
describe("channel", function () {
var channel = require('cordova/channel'),
c;
beforeEach(function() {
c = null;
c = channel.create('masterexploder');
});
describe("subscribe method", function() {
it("should throw an exception if no function is provided", function() {
expect(function() {
c.subscribe();
}).toThrow();
expect(function() {
c.subscribe(null);
}).toThrow();
expect(function() {
c.subscribe(undefined);
}).toThrow();
expect(function() {
c.subscribe({apply:function(){},call:function(){}});
}).toThrow();
});
it("should not change number of handlers if no function is provided", function() {
var initialLength = c.numHandlers;
try {
c.subscribe();
} catch(e) {}
expect(c.numHandlers).toEqual(initialLength);
try {
c.subscribe(null);
} catch(e) {}
expect(c.numHandlers).toEqual(initialLength);
});
});
describe("unsubscribe method", function() {
it("should throw an exception if passed in null or undefined", function() {
expect(function() {
c.unsubscribe();
}).toThrow();
expect(function() {
c.unsubscribe(null);
}).toThrow();
});
it("should not decrement numHandlers if unsubscribing something that does not exist", function() {
var initialLength = c.numHandlers;
c.unsubscribe('blah');
expect(c.numHandlers).toEqual(initialLength);
c.unsubscribe(2);
expect(c.numHandlers).toEqual(initialLength);
c.unsubscribe({balls:false});
expect(c.numHandlers).toEqual(initialLength);
});
it("should change the handlers length appropriately", function() {
var firstHandler = function() {};
var secondHandler = function() {};
var thirdHandler = function() {};
c.subscribe(firstHandler);
c.subscribe(secondHandler);
c.subscribe(thirdHandler);
var initialLength = c.numHandlers;
c.unsubscribe(thirdHandler);
expect(c.numHandlers).toEqual(initialLength - 1);
});
});
});