$30 off During Our Annual Pro Sale. View Details »
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
45
Telling Tales & Solving Crimes with New Relic
psyked
0
66
What I learned at the Edge conference 2015
psyked
0
55
Web Fonts FTW
psyked
0
120
Git 101: Force-sensitive to Jedi padawan
psyked
0
120
Responsive Images in 10 minutes
psyked
0
89
Hack to the Future
psyked
0
89
Other Decks in Programming
See All in Programming
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
130
チームをチームにするEM
hitode909
0
310
LLM Çağında Backend Olmak: 10 Milyon Prompt'u Milisaniyede Sorgulamak
selcukusta
0
120
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
1
700
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.3k
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
260
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
120
俺流レスポンシブコーディング 2025
tak_dcxi
14
8.6k
SwiftUIで本格音ゲー実装してみた
hypebeans
0
170
エディターってAIで操作できるんだぜ
kis9a
0
720
CSC509 Lecture 14
javiergs
PRO
0
220
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
110
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
331
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
70k
GitHub's CSS Performance
jonrohan
1032
470k
Unsuck your backbone
ammeep
671
58k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
BBQ
matthewcrist
89
9.9k
Site-Speed That Sticks
csswizardry
13
1k
Raft: Consensus for Rubyists
vanstee
141
7.2k
Bash Introduction
62gerente
615
210k
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