/
index.html
executable file
·281 lines (248 loc) · 8.01 KB
/
index.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=1024, user-scalable=no">
<title>Unit Testing With QUnit and Sinon</title>
<!-- Required stylesheet -->
<link rel="stylesheet" href="lib/deck.js/core/deck.core.css">
<!-- Extension CSS files go here. Remove or add as needed. -->
<link rel="stylesheet" href="lib/deck.js/extensions/goto/deck.goto.css">
<link rel="stylesheet" href="lib/deck.js/extensions/menu/deck.menu.css">
<link rel="stylesheet" href="lib/deck.js/extensions/navigation/deck.navigation.css">
<link rel="stylesheet" href="lib/deck.js/extensions/status/deck.status.css">
<link rel="stylesheet" href="lib/deck.js/extensions/hash/deck.hash.css">
<link rel="stylesheet" href="lib/deck.js/extensions/scale/deck.scale.css">
<!-- Style theme. More available in /themes/style/ or create your own. -->
<link rel="stylesheet" href="lib/deck.js/themes/style/swiss.css">
<!-- Transition theme. More available in /themes/transition/ or create your own. -->
<link rel="stylesheet" href="lib/deck.js/themes/transition/fade.css">
<!-- Required Modernizr file -->
<script src="lib/deck.js/modernizr.custom.js"></script>
</head>
<body class="deck-container">
<!-- Begin slides. Just make elements with a class of slide. -->
<section class="slide">
<h1>Javascript Unit Testing using Qunit and Sinon</h1>
</section>
<section class="slide">
<h2>Why test Javascript?</h2>
<ul>
<li class="slide">
<h3>Keep modules loosely coupled</h3>
</li>
<li class="slide">
<h3>Quality Assurance</h3>
</li>
<li class="slide">
<h3>Documentation</h3>
</li>
<li class="slide">
<h3>Guaranteed separation of JS & HTML</h3>
</li>
</ul>
</section>
<section class="slide">
<h2>QUnit</h2>
<p>A basic test:</p>
<pre>
test("demonstrate two main features of QUnit", function() {
ok(true === true);
equal(2+2, 4);
});
</pre>
<p><a href="basic.html" target="_blank">An example</a></p>
</section>
<section class="slide">
<h2>QUnit fixtures</h2>
<ul>
<li class="slide">
<h3>Provide good platform for DOM manipulation tests</h3>
</li>
<li class="slide">
<h3>Appear as flat HTML</h3>
</li>
<li class="slide">
<h3>Reset after each test (in teardown)</h3>
</li>
</ul>
<pre class="slide"><div id="target"></div></pre>
<pre class="slide">
get = document.getElementById;
test("set target text", function() {
get("target").innerHTML = "test";
equal(get("target").innerHTML, "test");
});
test("append to target text", function() {
get("target").innerHTML += " all the things";
<span class="slide" style="color: red;">equal(get("target").innerHTML, "test all the things");</span>
<span class="slide" style="color: green;">equal(get("target").innerHTML, " all the things");</span>
});
</pre>
</section>
<section class="slide">
<h2>Asynchronous Testing Overview</h2>
<ul>
<li class="slide">
<h3>AJAX requests</h3>
</li>
<li class="slide">
<h3>Timeouts / Animation</h3>
</li>
<li class="slide">
<h3>History API</h3>
</li>
<li class="slide">
<h3>Other longrunning operations / race conditions</h3>
</li>
</ul>
</section>
<section class="slide">
<h2>Asynchronous Testing Example</h2>
<pre>
test("test something after an operation", function() {
setTimeout(function() {
console.log('operation');
equal(1, 1);
}, 1000);
});
</pre>
<p><a href="async.html" target="_blank">Let's see what happens</a></p>
</section>
<section class="slide">
<h2>Expandibility</h2>
<pre class="slide">
<div id="qunit-fixture">
<div id="hello">Hello, <strong>World!</strong></div>
</div></pre>
<pre class="slide">
QUnit.extend( QUnit.assert, {
textEqual: function(element, expected, message) {
var actual = element.textContent;
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
}
});
test("div text is hello world", function(is) {
var el = document.getElementById('hello');
is.textEqual(el, "Hello, World!");
});</pre>
<p class="slide"><a href="plugin.html" target="_blank">It's demo time</a></p>
</section>
<section class="slide">
<h2>Mocking</h2>
<ul>
<li>
<h3>Dummy Objects</h3>
</li>
<li>
<ul>
<li class="slide">
<h3>Simple to write</h3>
</li>
<li class="slide">
<h3>Simple to understand</h3>
</li>
<li class="slide">
<h3>Good stubbing solution</h3>
</li>
<li class="slide">
<h3>Not so good for testing against</h3>
</li>
</ul>
</li>
<li>
<h3>Sinon</h3>
<ul>
<li class="slide">
<h3>Provides all the benefits of dummies</h3>
</li>
<li class="slide">
<h3>Plus mocks to verify against</h3>
</li>
<li class="slide">
<h3>And spies to track against</h3>
</li>
</ul>
</li>
</ul>
</section>
<section class="slide">
<!-- please note: these examples are shamelessly stolen from the Sinon docs -->
<h2>Sinon examples</h2>
<div class="slide">
<h3>Stubs</h3>
<pre>
var awesomeCalculator = sinon.stub().returns('totally awesome');
equal(awesomeCalculator('Simon'), 'totally awesome');</pre>
</div>
<div class="slide">
<h3>Spies and mocks</h3>
<pre>
var MyObject = {
method: function () {},
mySpy: sinon.spy()
};
var mock = sinon.mock(MyObject);
mock.expects("method").once().returns(42);
equal(MyObject.method(), 42);
mock.verify();
MyObject.mySpy();
ok(MyObject.mySpy.called);
</pre>
</div>
<p class="slide"><a href="sinon.html">More examples</a></p>
</section>
<section class="slide">
<h2>Potential improvements</h2>
<ul>
<li>
<h3 class="slide">Use more stubs</h3>
</li>
<li>
<h3 class="slide">Less async tests, more stubs with callbacks</h3>
</li>
<li>
<h3 class="slide">Less DOM integration</h3>
</li>
<li>
<h3 class="slide">Object.prototype</h3>
</li>
</ul>
</section>
<section class="slide">
<h1>fin<span class="slide">.</span></h1>
</section>
<!-- End slides. -->
<!-- Begin extension snippets. Add or remove as needed. -->
<!-- deck.navigation snippet -->
<a href="#" class="deck-prev-link" title="Previous">←</a>
<a href="#" class="deck-next-link" title="Next">→</a>
<!-- deck.status snippet -->
<p class="deck-status">
<span class="deck-status-current"></span>
/
<span class="deck-status-total"></span>
</p>
<!-- deck.hash snippet -->
<a href="../../../Downloads/imakewebthings-deck.js-e42bd0c" title="Permalink to this slide" class="deck-permalink">#</a>
<!-- End extension snippets. -->
<!-- Required JS files. -->
<script src="lib/deck.js/jquery-1.7.2.min.js"></script>
<script src="lib/deck.js/core/deck.core.js"></script>
<!-- Extension JS files. Add or remove as needed. -->
<script src="lib/deck.js/core/deck.core.js"></script>
<script src="lib/deck.js/extensions/hash/deck.hash.js"></script>
<script src="lib/deck.js/extensions/menu/deck.menu.js"></script>
<script src="lib/deck.js/extensions/goto/deck.goto.js"></script>
<script src="lib/deck.js/extensions/status/deck.status.js"></script>
<script src="lib/deck.js/extensions/navigation/deck.navigation.js"></script>
<script src="lib/deck.js/extensions/scale/deck.scale.js"></script>
<!-- Initialize the deck. You can put this in an external file if desired. -->
<script>
$(function() {
$.deck('.slide');
});
</script>
</body>
</html>