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
63
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
200
Virtualisation - Vagrant and Docker
psyked
0
110
The Magic of Charts - Data Visualisation in JavaScript
psyked
0
38
Telling Tales & Solving Crimes with New Relic
psyked
0
50
What I learned at the Edge conference 2015
psyked
0
42
Web Fonts FTW
psyked
0
110
Git 101: Force-sensitive to Jedi padawan
psyked
0
110
Responsive Images in 10 minutes
psyked
0
73
Hack to the Future
psyked
0
74
Other Decks in Programming
See All in Programming
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
490
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.4k
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
520
Go1.25からのGOMAXPROCS
kuro_kurorrr
1
810
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
140
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
1
120
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
650
CursorはMCPを使った方が良いぞ
taigakono
1
180
すべてのコンテキストを、 ユーザー価値に変える
applism118
2
880
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
2
280
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
4
970
Featured
See All Featured
For a Future-Friendly Web
brad_frost
179
9.8k
Statistics for Hackers
jakevdp
799
220k
Site-Speed That Sticks
csswizardry
10
660
Documentation Writing (for coders)
carmenintech
72
4.9k
Raft: Consensus for Rubyists
vanstee
140
7k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
Code Reviewing Like a Champion
maltzj
524
40k
Being A Developer After 40
akosma
90
590k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
How GitHub (no longer) Works
holman
314
140k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.6k
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