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
Todd Kaufman
July 27, 2012
Technology
4
260
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
150
Becoming Less Horrible at Diversity
toddkaufman
1
140
Fallacies of Software Development
toddkaufman
0
130
Finding Joy at Work
toddkaufman
1
4.2k
Culture
toddkaufman
1
140
Enacting Change
toddkaufman
0
1.5k
Failing with Agility
toddkaufman
2
130
Agile Metrics
toddkaufman
4
930
Other Decks in Technology
See All in Technology
Uncle Bobの「プロフェッショナリズムへの期待」から学ぶプロの覚悟
nakasho
2
110
大規模サーバーレスAPIの堅牢性・信頼性設計 〜AWSのベストプラクティスから始まる現実的制約との向き合い方〜
maimyyym
8
4.3k
SwiftUIのGeometryReaderとScrollViewを基礎から応用まで学び直す:設計と活用事例
fumiyasac0921
0
160
三菱電機・ソニーグループ共同の「Agile Japan企業内サテライト」_2025
sony
0
150
『OCI で学ぶクラウドネイティブ 実践 × 理論ガイド』 書籍概要
oracle4engineer
PRO
3
210
能登半島地震において デジタルができたこと・できなかったこと
ditccsugii
0
120
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
11
80k
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
3
5.5k
AWS Control Tower に学ぶ! IAM Identity Center 権限設計の第一歩 / IAM Identity Center with Control Tower
y___u
0
150
能登半島地震で見えた災害対応の課題と組織変革の重要性
ditccsugii
0
600
Git in Team
kawaguti
PRO
3
350
Adapty_東京AI祭ハッカソン2025ピッチスライド
shinoyamada
0
280
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
140k
Faster Mobile Websites
deanohume
310
31k
How to Ace a Technical Interview
jacobian
280
24k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
4 Signs Your Business is Dying
shpigford
185
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.7k
Producing Creativity
orderedlist
PRO
347
40k
Six Lessons from altMBA
skipperchong
28
4k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
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