Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
The (quest for the) Holy Grail
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
James Ford
October 02, 2013
Programming
76
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The (quest for the) Holy Grail
Cross-browser JavaScript Unit Testing with Code Coverage Metrics
James Ford
October 02, 2013
Transcript
21 slides
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
More Decks by James Ford
See All by James Ford
ES6; // WTF?
psyked
0
260
Virtualisation - Vagrant and Docker
psyked
0
130
The Magic of Charts - Data Visualisation in JavaScript
psyked
0
65
Telling Tales & Solving Crimes with New Relic
psyked
0
81
What I learned at the Edge conference 2015
psyked
0
79
Web Fonts FTW
psyked
0
140
Git 101: Force-sensitive to Jedi padawan
psyked
0
150
Responsive Images in 10 minutes
psyked
0
110
Hack to the Future
psyked
0
110
Other Decks in Programming
See All in Programming
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.4k
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
620
GraphQL の onError と Nullability のこれから
quramy
0
220
自宅サーバはどこまで再現できるのか - Proxmox VE上のVM環境をIaCとバックアップで戻してみた
youto
0
440
将来の標準フォーマッター?ktfmtを深堀る
t45k
0
230
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
780
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
Distance field of Julia set
kinakomoti321
0
330
SODA - FACT BOOK(JP)
sodainc
1
40k
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1k
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
2
500
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
150
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
620
So, you think you're a good person
axbom
PRO
2
2.3k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
580
The Cult of Friendly URLs
andyhume
79
7.1k
Site-Speed That Sticks
csswizardry
13
1.6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Exploring anti-patterns in Rails
aemeredith
4
570
Crafting Experiences
bethany
1
450
A Modern Web Designer's Workflow
chriscoyier
699
190k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
How STYLIGHT went responsive
nonsquared
100
6.4k