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
62
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
120
Virtualisation - Vagrant and Docker
psyked
0
82
The Magic of Charts - Data Visualisation in JavaScript
psyked
0
30
Telling Tales & Solving Crimes with New Relic
psyked
0
25
What I learned at the Edge conference 2015
psyked
0
28
Web Fonts FTW
psyked
0
69
Git 101: Force-sensitive to Jedi padawan
psyked
0
88
Responsive Images in 10 minutes
psyked
0
51
Hack to the Future
psyked
0
58
Other Decks in Programming
See All in Programming
1인 개발자로 행복하게 살기 - GDG 송도 헬로월드 2024
benjaminkim
1
5.6k
Java 22 Overview
kishida
1
170
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
3
770
PHP8.3の機能を振り返る / Review of PHP 8.3 features
seike460
PRO
1
110
エンターテイメント業界で利用されるAWS
demuyan
0
200
try!Swift Tokyo 2024 参加報告 LT
akidon0000
1
190
Doctrine ORMでValue Objectを扱う方法4選 #phpstudy / 4 ways to handle Value Objects with Doctrine ORM
77web
4
110
Ruby Pattern Matching
bkuhlmann
0
920
ゆるい個人開発のススメ
kuroppe1819
10
940
スクラムチームと認知負荷 - ニフティのスクラムトーク Vol2. / NIFTY Tech Talk #18
niftycorp
PRO
1
120
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
22
15k
脱・初心者!脱・マネコン!AWS CDKを使ってみませんか!?
har1101
0
300
Featured
See All Featured
Code Review Best Practice
trishagee
54
15k
Why Our Code Smells
bkeepers
PRO
331
56k
Adopting Sorbet at Scale
ufuk
67
8.6k
The Cult of Friendly URLs
andyhume
74
5.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Building a Scalable Design System with Sketch
lauravandoore
455
32k
Reflections from 52 weeks, 52 projects
jeffersonlam
344
19k
Statistics for Hackers
jakevdp
789
220k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
5
1.5k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
Git: the NoSQL Database
bkeepers
PRO
422
63k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
658
120k
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