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
220
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
120
Becoming Less Horrible at Diversity
toddkaufman
1
89
Fallacies of Software Development
toddkaufman
0
100
Finding Joy at Work
toddkaufman
1
4.1k
Culture
toddkaufman
1
120
Enacting Change
toddkaufman
0
1.4k
Failing with Agility
toddkaufman
2
99
Agile Metrics
toddkaufman
4
880
Other Decks in Technology
See All in Technology
一休.comレストランにおけるRustの活用
kymmt90
3
580
新卒1年目が挑む!生成AI × マルチエージェントで実現する次世代オンボーディング / operation-ai-onboarding
cyberagentdevelopers
PRO
1
170
20241031_AWS_生成AIハッカソン_GenMuck
tsumita
0
110
小規模に始めるデータメッシュとデータガバナンスの実践
kimujun
3
590
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
140
フルカイテン株式会社 採用資料
fullkaiten
0
36k
IaC運用を楽にするためにCDK Pipelinesを導入したけど、思い通りにいかなかった話
smt7174
1
110
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
630
コンテンツを支える 若手ゲームクリエイターの アートディレクションの事例紹介 / cagamefi-game
cyberagentdevelopers
PRO
1
130
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
5
49k
Gradle: The Build System That Loves To Hate You
aurimas
2
150
いまならこう作りたい AWSコンテナ[本格]入門ハンズオン 〜2024年版 ハンズオンの構想〜
horsewin
9
2.1k
Featured
See All Featured
Navigating Team Friction
lara
183
14k
Code Reviewing Like a Champion
maltzj
519
39k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
How to train your dragon (web standard)
notwaldorf
88
5.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Adopting Sorbet at Scale
ufuk
73
9k
Into the Great Unknown - MozCon
thekraken
31
1.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Scaling GitHub
holman
458
140k
Happy Clients
brianwarren
97
6.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
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