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
Better JavaScript with Jasmine
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Todd Kaufman
July 27, 2012
Technology
4
280
Better JavaScript with Jasmine
Quick introduction into the Jasmine testing framework for JavaScript, geared towards the rubyist.
Todd Kaufman
July 27, 2012
Tweet
Share
More Decks by Todd Kaufman
See All by Todd Kaufman
Under Pressure
toddkaufman
0
170
Becoming Less Horrible at Diversity
toddkaufman
1
160
Fallacies of Software Development
toddkaufman
0
140
Finding Joy at Work
toddkaufman
1
4.2k
Culture
toddkaufman
1
150
Enacting Change
toddkaufman
0
1.5k
Failing with Agility
toddkaufman
2
140
Agile Metrics
toddkaufman
4
960
Other Decks in Technology
See All in Technology
中央集権型を脱却した話 分散型をやめて、連邦型にたどり着くまで
sansantech
PRO
1
290
スケールアップ企業でQA組織が機能し続けるための組織設計と仕組み〜ボトムアップとトップダウンを両輪としたアプローチ〜
tarappo
4
340
スピンアウト講座04_ルーティン処理
overflowinc
0
1k
品質を経営にどう語るか #jassttokyo / Communicating the Strategic Value of Quality to Executive Leadership
kyonmm
PRO
3
1.2k
AgentCoreとLINEを使った飲食店おすすめアプリを作ってみた
yakumo
2
210
A Casual Introduction to RISC-V
omasanori
0
550
スピンアウト講座06_認証系(API-OAuth-MCP)入門
overflowinc
0
980
スピンアウト講座01_GitHub管理
overflowinc
0
1.2k
データマネジメント戦略Night - 4社のリアルを語る会
kubell_hr
0
180
Phase04_ターミナル基礎
overflowinc
0
2k
Phase09_自動化_仕組み化
overflowinc
0
1.5k
SLI/SLO 導入で 避けるべきこと3選
yagikota
0
140
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
New Earth Scene 8
popppiees
1
1.8k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
300
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Rails Girls Zürich Keynote
gr2m
96
14k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
68
38k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
99
Test your architecture with Archunit
thirion
1
2.2k
Facilitating Awesome Meetings
lara
57
6.8k
A Tale of Four Properties
chriscoyier
163
24k
WCS-LA-2024
lcolladotor
0
490
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.5k
Transcript
Better Javascript with Jasmine
I don’t test my JavaScript because ______________
“Semicolons are for losers”
“It can’t be automated”
“I already test it with Cucumber”
“I don’t have any REAL BUSINESS LOGIC in my JavaScript”
“It’s too hard”
“It changes too often”
“I’m lazy”
“It’s not worth the effort”
I have [ ] more [ ] less JavaScript in
my code than I used to.
I have [ X ] more [ ] less JavaScript
in my code than I used to.
None
Rubyists need not fear
the authors may have seen RSpec before
describe RomanNumeral do it "should convert I to 1" do
subject = RomanNumeral.new("I") subject.to_i.should eq(1) end end
describe("RomanNumeral", function() { it("returns 1 for I", function() { var
subject = new RomanNumeral("I"); return expect(subject.toI()).toBe(1); }); });
basics
RSpec Jasmine describe User do describe(“User”, function() it “saves stuff”
do it (“saves stuff”, function() value.should expect(value)
matchers
RSpec Jasmine name.should eq(“Todd”) expect(name).toBe(“Todd”); (3*3).should_not == 8 expect(3*3).not.toBe(8); be,
eql, equal, ==, === toEqual, toBe
None
None
RSpec Jasmine 7.should be_true expect(7).toBeTruthy(); (7).should_not be(true) expect(7).not.toBe(true); nil.should be_false
expect(null).toBeFalsy();
RSpec Jasmine [‘a’,’b’].should include(‘a’) expect([3,4]).toContain(4); (1.05).should be_close(1, 0.06) expect(1.05).toBeCloseTo(1, 0)
nil.should be_false expect(null).toBeFalsy();
toBeDefined / toBeUndefined toMatch(/regex/) toThrow custom matchers as well
beforeEach afterEach
xdescribe xit
None
test doubles
None
spies
None
None
None
None
None
None
None
None
stubs
None
jasmine-stealth
None
fakes
None
mocks
ease of use
None
None
None
but, semicolons are still for losers
describe("RomanNumeral", function() { it("returns 1 for I", function() { var
subject = new RomanNumeral("I"); return expect(subject.toI()).toBe(1); }); });
describe "RomanNumeral", -> it "returns 1 for I", -> subject
= new RomanNumeral("I") expect(subject.toI()).toBe 1
Great, so how do I run this stuff?
www.tryjasmine.com
None
Jasmine standalone
https://github.com/ pivotal/jasmine/ downloads
None
Jasmine within Rails
gem install jasmine
jasmine-headless-webkit
None
None
gem install jasmine-rails
Available for other enviroments as well
what now?
it’s not that hard
it is important
you have no excuses
Thanks! @toddkaufman @testdouble