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
220
Virtualisation - Vagrant and Docker
psyked
0
110
The Magic of Charts - Data Visualisation in JavaScript
psyked
0
43
Telling Tales & Solving Crimes with New Relic
psyked
0
63
What I learned at the Edge conference 2015
psyked
0
51
Web Fonts FTW
psyked
0
120
Git 101: Force-sensitive to Jedi padawan
psyked
0
120
Responsive Images in 10 minutes
psyked
0
86
Hack to the Future
psyked
0
86
Other Decks in Programming
See All in Programming
Claude Code on the Web を超える!? Codex Cloud の実践テク5選
sunagaku
0
400
ノーコードからの脱出 -地獄のデスロード- / Escape from Base44
keisuke69
0
670
開発生産性が組織文化になるまでの軌跡
tonegawa07
0
130
Swift Concurrency 年表クイズ
omochi
3
220
pnpm に provenance のダウングレード を検出する PR を出してみた
ryo_manba
1
220
KoogではじめるAIエージェント開発
hiroaki404
1
410
複数チーム並行開発下でのコード移行アプローチ ~手動 Codemod から「生成AI 活用」への進化
andpad
0
100
What’s Fair is FAIR: A Decentralised Future for WordPress Distribution
rmccue
0
150
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
400
ビルドプロセスをデバッグしよう!
yt8492
0
280
例外処理を理解して、設計段階からエラーを見つけやすく、起こりにくく #phpconfuk
kajitack
12
5.7k
Introducing RemoteCompose: break your UI out of the app sandbox.
camaelon
2
530
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
KATA
mclloyd
PRO
32
15k
The Invisible Side of Design
smashingmag
302
51k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Being A Developer After 40
akosma
91
590k
The Cost Of JavaScript in 2023
addyosmani
55
9.2k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
A Tale of Four Properties
chriscoyier
161
23k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
310
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Making Projects Easy
brettharned
120
6.4k
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