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
73
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
More Decks by James Ford
See All by James Ford
ES6; // WTF?
psyked
0
250
Virtualisation - Vagrant and Docker
psyked
0
120
The Magic of Charts - Data Visualisation in JavaScript
psyked
0
60
Telling Tales & Solving Crimes with New Relic
psyked
0
79
What I learned at the Edge conference 2015
psyked
0
76
Web Fonts FTW
psyked
0
140
Git 101: Force-sensitive to Jedi padawan
psyked
0
130
Responsive Images in 10 minutes
psyked
0
100
Hack to the Future
psyked
0
110
Other Decks in Programming
See All in Programming
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
240
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
170
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
490
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
110
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
360
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
180
Google Apps Script で Ruby を動かす
kawahara
0
220
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
330
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
590
Featured
See All Featured
Leo the Paperboy
mayatellez
8
2.1k
Music & Morning Musume
bryan
47
7.3k
Paper Plane (Part 1)
katiecoart
PRO
1
10k
Test your architecture with Archunit
thirion
1
2.3k
Darren the Foodie - Storyboard
khoart
PRO
3
3.6k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
480
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Amusing Abliteration
ianozsvald
1
250
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
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