-
Notifications
You must be signed in to change notification settings - Fork 48
/
unit-tests.htm
121 lines (98 loc) · 2.81 KB
/
unit-tests.htm
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!--
* MinPubSub
* Copyright(c) 2011 Daniel Lamb <daniellmb.com>
* MIT Licensed
*-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Unit Testing MinPubSub</title>
<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/3.3.0/build/cssfonts/fonts-min.css" />
</head>
<body class="yui3-skin-sam yui-skin-sam">
<h1>MinPubSub Unit Tests</h1>
<p>
An ultra minimalist pub/sub framework weighing in at only 198 bytes gzipped.
</p>
<div id="testLogger"></div>
<script type="text/javascript" src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
<script type="text/javascript">c_ = {};</script>
<script type="text/javascript" src="minpubsub.js"></script>
<script type="text/javascript">
YUI({ filter: 'raw' }).use("node", "console", "test" , function (Y) {
Y.namespace("pubsub.test");
Y.pubsub.test.PublishTestCase = new Y.Test.Case({
name : "Publish Tests",
setUp : function () {
var me = this;
me.count = 0;
c_["/some/topic"] = [
function (msg) {
me.count++;
}
];
},
tearDown : function () {
delete c_["/some/topic"];
delete this.count;
},
//tests
testHasSub : function () {
var Assert = Y.Assert;
window.publish("/some/topic");
Assert.areEqual(1, this.count);
},
testNoSub : function () {
var Assert = Y.Assert;
window.publish("/bogus/topic");
Assert.areEqual(0, this.count);
}
});
Y.pubsub.test.SubscribeTestCase = new Y.Test.Case({
name : "Subscribe Tests",
tearDown : function () {
delete c_["/some/topic"];
},
//tests
testAddSub : function () {
var Assert = Y.Assert,
func = function(){};
window.subscribe("/some/topic", func);
Assert.areEqual(func, c_["/some/topic"][0]);
}
});
Y.pubsub.test.UnsubscribeTestCase = new Y.Test.Case({
name : "Unsubscribe Tests",
setUp : function () {
this.func = function () {};
c_["/some/topic"] = [this.func];
},
tearDown : function () {
delete c_["/some/topic"];
},
//tests
testRemoveSub : function () {
var Assert = Y.Assert;
window.unsubscribe(["/some/topic", this.func]);
Assert.areNotEqual(this.func, c_["/some/topic"][0]);
},
testRemoveSubTwoArgs : function () {
var Assert = Y.Assert;
window.unsubscribe("/some/topic", this.func);
Assert.areNotEqual(this.func, c_["/some/topic"][0]);
}
});
Y.pubsub.test.PubSubSuite = new Y.Test.Suite("MinPubSub Suite");
Y.pubsub.test.PubSubSuite.add(Y.pubsub.test.PublishTestCase);
Y.pubsub.test.PubSubSuite.add(Y.pubsub.test.SubscribeTestCase);
Y.pubsub.test.PubSubSuite.add(Y.pubsub.test.UnsubscribeTestCase);
var r = new Y.Console({
newestOnTop : false,
style: 'block'
});
r.render('#testLogger');
Y.Test.Runner.add(Y.pubsub.test.PubSubSuite);
Y.Test.Runner.run();
});
</script>