Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The (quest for the) Holy Grail
Search
James Ford
October 02, 2013
Programming
0
65
The (quest for the) Holy Grail
Cross-browser JavaScript Unit Testing with Code Coverage Metrics
James Ford
October 02, 2013
Tweet
Share
More Decks by James Ford
See All by James Ford
ES6; // WTF?
psyked
0
210
Virtualisation - Vagrant and Docker
psyked
0
110
The Magic of Charts - Data Visualisation in JavaScript
psyked
0
41
Telling Tales & Solving Crimes with New Relic
psyked
0
56
What I learned at the Edge conference 2015
psyked
0
47
Web Fonts FTW
psyked
0
120
Git 101: Force-sensitive to Jedi padawan
psyked
0
110
Responsive Images in 10 minutes
psyked
0
81
Hack to the Future
psyked
0
81
Other Decks in Programming
See All in Programming
Android端末で実現するオンデバイスLLM 2025
masayukisuda
1
170
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
2
1.3k
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
4
1.4k
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
240
AIでLINEスタンプを作ってみた
eycjur
1
230
RDoc meets YARD
okuramasafumi
4
170
時間軸から考えるTerraformを使う理由と留意点
fufuhu
16
4.8k
Android 16 × Jetpack Composeで縦書きテキストエディタを作ろう / Vertical Text Editor with Compose on Android 16
cc4966
2
260
ユーザーも開発者も悩ませない TV アプリ開発 ~Compose の内部実装から学ぶフォーカス制御~
taked137
0
190
🔨 小さなビルドシステムを作る
momeemt
4
690
複雑なドメインに挑む.pdf
yukisakai1225
5
1.2k
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
1
450
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
580
GitHub's CSS Performance
jonrohan
1032
460k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.2k
Docker and Python
trallard
46
3.6k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
30
9.7k
Building an army of robots
kneath
306
46k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Transcript
None
None
None
None
Documents & Defines the expected input and output of your
code Makes it Easier to Refactor. Helps you write Better, re-usable code. Enables Automated testing.
Unit Testing requires you change the way you write your
code. (But this is good);
JavaScript is interpreted at runtime. Across a variety of different
browsers. Mutable , Loosely-typed ,, Global scope. SUDDEN DEATH Mode
Tests should:: • Run in a real browser environment •
Run in any & all browsers • Integrate with our CI setup • Output code coverage metrics • Easy to write • Be reliable, execute fast
None
http://karma-runner.github.io/.
http://pivotal.github.io/jasmine/.
1. Karma runs a server 2. Real-world browsers connect 3.
Karma serves your tests 4. Browsers execute tests 5. Karma collates the output
> karma init karma.config.js > karma start
• Tests written in JavaScript • BDD syntax • Anything
you can do with JavaScript, you can test with JavaScript
describe("A suite", function() { it("contains spec with an expectation", function()
{ expect(true).toBe(true); expect(true).not.toBe(false); }); });
• describe(name, function) • it(name, function) • beforeEach(function) / afterEach(function)
• expect(condition).toBe(value); • expect(condition).not.toBe(value); • .toEqual() / .toBeTruthy() / .toBeFalsy() • waitsFor(function) / runs(function) Writing tests in Jasmine
it('checks that the Quicknav control navigates to a page', function()
{ loadFixtures('simple-fixture.html'); var activeTextInstance = new ActiveText(...); waitsFor(function() { return activeTextInstance.ready; }, 500); runs(function() { var element = $('.quicknav input'); element.focus(); element.val("5"); var e = jQuery.Event("keydown"); e.which = ActiveText.Keymap.ENTER; $(element).trigger(e); e = jQuery.Event("keyup"); e.which = ActiveText.Keymap.ENTER; $(element).trigger(e); expect(element.val()).toBe("Pages 4–5 of 26"); expect(activeTextInstance.model.getCurrentIndex()).toBe(3); expect(activeTextInstance.model.getCurrentPageNumber()).toBe(4); }); });
Console Output;
CI Integration;
LCOV Output;
None