-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·403 lines (315 loc) · 13.4 KB
/
index.html
File metadata and controls
executable file
·403 lines (315 loc) · 13.4 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>UNIT TESTING THE FRONTEND</title>
<link href='http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/theme/default.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<script>
// If the query includes 'print-pdf' we'll use the PDF print sheet
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div id="main_thing" class="reveal">
<!-- Used to fade in a background when a specific slide state is reached -->
<div class="state-background"></div>
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Unit testing the frontend</h1><br>
<p>Navigating the minefield of client side testing</p><br>
<p style="font-size:18px;">
<strong>Presenters:</strong>
Rob Odil &
Brendan Hill
</p>
</section>
<section>
<section>
<h2>Today's Topics Include...</h2><br>
<ul>
<li><strong>Ember</strong> :: MVC framework for the browser</li>
<li><strong>Qunit</strong> :: Unit testing framework for js</li>
<li><strong>Sinon</strong> :: Mocking library for use in unit testing</li>
<li><strong>PhantomJS</strong> :: Headless Webkit browser</li>
</ul>
</section>
<section>
<h1>Huh?!?!</h1>
<img src="rubix_cat.jpg">
</section>
</section>
<section>
<h2>What's This Ember Thing?</h2><br>
<ul>
<li>Model/View/Controller framework</li>
<li>Databinding to the dom</li>
<li>Clientside templating (Handlebars)</li>
</ul>
</section>
<section>
<h2>Object Binding Example</h2>
<pre><code>MyApp.president = Ember.Object.create({
name: "Barack Obama"
});
MyApp.country = Ember.Object.create({
// Ending a property with 'Binding' tells Ember to
// create a binding to the presidentName property.
presidentNameBinding: 'MyApp.president.name'
});
// Later, after Ember has resolved bindings...
MyApp.country.get('presidentName');
// "Barack Obama"</code></pre>
</section>
<section>
<h2>DOM Binding Example</h2>
<span style="font-size: 16px;">In the handlebars template:</span>
<pre><code><p>Property {{App.model.property}}</p></code></pre>
<span style="font-size: 16px;">With javascript code:</span>
<pre><code>App.model = Ember.Object.create({
property: 'is set'
});</code></pre>
<span style="font-size: 16px;">Browser output:</span><br>
Property is set
</section>
<section>
<h2>What's Qunit Do For Me?</h2><br>
<ul>
<li>Javascript unit testing framework</li>
<li>Basic module system</li>
<li>Simple set of assertions</li>
<li>Reports passed/failed tests</li>
</ul>
</section>
<section>
<h2>Testing an API Example</h2>
<pre><code>
var easyMath = {
timesTwo: function (input) {
return input * 2;
}
};
test('Make sure math works', function () {
equal(6, easyMath.timesTwo(3), '3 * 2 = 6');
});</code></pre>
</section>
<section>
<h2>Testing the DOM Example</h2>
<pre><code>var pageBuilder = {
insertFooter: function () {
$('body').append('<div id="footer"></div>');
}
};
test('Make sure footer can append', function () {
pageBuilder.insertFooter();
equal($('#footer').length, 1, 'Footer did append');
});</code></pre>
</section>
<section>
<h2>Async Testing Example</h2>
<pre><code>test('Testing async operations', function () {
stop();
setTimeout(function () {
ok('Something' !== 'else', 'always pass');
start();
}, 1000);
ok('thing' === 'thing', 'always pass');
});</code></pre>
</section>
<section>
<h2>Ember Testing Gotcha</h2><br>
<ul>
<li>Views and bindings aren't real time</li>
<li>Ember resolves bindings in runloops</li>
</section>
<section>
<h2>Ember Test Example</h2>
<pre><code style="font-size:16px;">App.Model = Ember.Object.extend({
fname: '',
lname: '',
fullName: function () {
return this.get('fname') + ' ' + this.get('lname');
}.property('fname', 'lname')
});
test('Test that full name works', function () {
Ember.run.begin();
var mdl = App.Model.create({});
mdl.set('fname', 'John').set('lname', 'Doe');
Ember.run.end();
equal(mdl.get('fullName'), 'John Doe', 'Magic happened.');
});</code></pre>
</section>
<section>
<h2>Sinon? Never heard of it!</h2><br>
<ul>
<li>Test spies</li>
<li>Stubs and mocks</li>
<li>Isolating AJAX tests</li>
</ul>
</section>
<section>
<h2>Sinon Test Spy Example</h2>
<pre><code style="font-size:16px;">var testCallbacks = function (callback) {
// Do the work. maybe update the dom
$('body').append('something added');
return callback();
};
test('Sample sinon spy in action', function () {
var theSpy = sinon.spy();
testCallbacks(theSpy);
ok(theSpy.calledOnce, 'Our spy was called.');
});</code></pre>
</section>
<section>
<h2>Sinon Stub Example</h2>
<pre><code style="font-size:16px;">var testStubs = function (callback) {
// Do the work. maybe update the dom
$('body').append('something added');
return callback();
};
test('Sinon stub used to force return value', function () {
var theStub = sinon.stub().returns(42);
equal(testStubs(theStub), 42, 'Returned value is correct');
});</code></pre>
</section>
<section>
<h2>Sinon Mock Example</h2>
<pre><code style="font-size:16px;">var apiToBe = {
futureMethod: function () {
// doesn't do anything yet
}
};
test('sinon api fakes implementation of api', function () {
var mock = sinon.mock(apiToBe);
mock.expects('futureMethod').once().returns(42);
equal(apiToBe.futureMethod(), 42, 'The returned value is correct');
ok(mock.verify(), 'Verify that the method was only called once');
});</code></pre>
</section>
<section>
<h3>Sinon AJAX Test Example</h3>
<pre><code style="font-size:16px;">function getServerData() {
jQuery.ajax({
url: "/data/",
success: function (data) {$('body').append(data.key);}
});
}
test('Test a fake ajax request', function () {
var fakeServer = sinon.fakeServer.create();
getServerData();
fakeServer.requests[0].respond(200,
{'Content-Type': 'application/json'},
JSON.stringify({key: 'value'})
);
equal('/data/', fakeServer.requests[0].url, 'Used correct URL');
equal($('body').text(), 'value', 'Dom was updated');
fakeServer.restore();
}</code></pre>
</section>
<section>
<h2>PhantomJS? Sounds scary!</h2><br>
<ul>
<li>Webkit at the command line</li>
<li>Run test suit outside the browser</li>
<li>Integration with other tools</li>
</ul>
</section>
<section>
<h2>Phantom Use Cases</h2><br>
<ul>
<li>Using a file watcher for change feedback
<ul>
<li>Grunt</li>
<li>Yeoman</li>
</ul>
</li>
<li>Integrating with continuous integration system
<ul>
<li>Jenkins / Hudson</li>
<li>Travis CI</li>
<li>Team City</li>
</ul>
</li>
</ul>
</section>
<section>
<h2>A Sample Application</h2><br>
Demo Time
</section>
<section>
<h2>Links & Contact</h2>
<div style="font-size:20px;line-height:24px;">
Ember: <a href="http://emberjs.com/" style="vertical-align:inherit;">http://emberjs.com/</a><br>
Qunit: <a href="http://qunitjs.com/" style="vertical-align:inherit;">http://qunitjs.com/</a><br>
Sinon: <a href="http://sinonjs.org/" style="vertical-align:inherit;">http://sinonjs.org/</a><br>
Phantom: <a href="http://phantomjs.org/" style="vertical-align:inherit;">http://phantomjs.org/</a><br><br>
Sample Project: <a href="http://x.co/cc2012proj" style="vertical-align:inherit;">http://x.co/cc2012proj</a><br>
This Presentation: <a href="http://x.co/cc2012pres" style="vertical-align:inherit;">http://x.co/cc2012pres</a><br><br>
Rob: <a href="mailto:rodil@godaddy.com">rodil@godaddy.com</a><br>
Brendan: <a href="mailto:bhill@godaddy.com">bhill@godaddy.com</a>
</div>
</section>
<section>
<h3>Comments, Questions, Suggestions?</h3><br>
<p>
Fire away!!!
</p>
</section>
</div>
<!-- The navigational controls UI -->
<aside class="controls">
<a class="left" style="display:none;" href="#">◄</a>
<a class="right" style="display:none;" href="#">►</a>
<a class="up" style="display:none" href="#">▲</a>
<a class="down" style="display: none;" href="#">▼</a>
<a href="#" onclick="togFull();" style="text-align:center;">▲</a>
</aside>
<!-- Presentation progress bar -->
<div class="progress"><span></span></div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
function togFull() {
if (!document.webkitIsFullScreen) {
document.body.webkitRequestFullScreen();
} else {
document.webkitCancelFullScreen();
}
}
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
theme: Reveal.getQueryHash().theme || 'default', // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/linear(2d)
// Optional libraries used to extend on reveal.js
dependencies: [
// { src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
// { src: 'lib/js/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
// { src: 'lib/js/data-markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
// { src: '/socket.io/socket.io.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
// { src: 'plugin/speakernotes/client.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
{ src: 'lib/js/highlight.js', async: true, callback: function() { window.hljs.initHighlightingOnLoad(); } }
]
});
</script>
<style>
.reveal .progress span {
background-color: #09c;
}
div.reveal div.slides {
max-width: 1000px;
}
</style>
</body>
</html>