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
68
0
Share
The (quest for the) Holy Grail
Cross-browser JavaScript Unit Testing with Code Coverage Metrics
James Ford
October 02, 2013
More Decks by James Ford
See All by James Ford
ES6; // WTF?
psyked
0
240
Virtualisation - Vagrant and Docker
psyked
0
120
The Magic of Charts - Data Visualisation in JavaScript
psyked
0
56
Telling Tales & Solving Crimes with New Relic
psyked
0
71
What I learned at the Edge conference 2015
psyked
0
68
Web Fonts FTW
psyked
0
140
Git 101: Force-sensitive to Jedi padawan
psyked
0
130
Responsive Images in 10 minutes
psyked
0
99
Hack to the Future
psyked
0
100
Other Decks in Programming
See All in Programming
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
2.7k
Agent Skills を社内で育てる仕組み作り
jackchuka
0
350
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
740
Kingdom of the Machine
yui_knk
2
1.4k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
620
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.5k
リセットCSSを1行消したらアクセシビリティが向上した話
pvcresin
4
450
when storing skills in S3 file
watany
2
470
Back to the roots of date
jinroq
0
650
AIを導入する前にやるべきこと
negima
2
320
実践CRDT
tamadeveloper
0
610
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
140
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
330
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
140
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
21
A Modern Web Designer's Workflow
chriscoyier
698
190k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
How to Talk to Developers About Accessibility
jct
2
190
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
170
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
300
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