×
Copy
Open
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Better Javascript with Jasmine
Slide 2
Slide 2 text
I don’t test my JavaScript because ______________
Slide 3
Slide 3 text
“Semicolons are for losers”
Slide 4
Slide 4 text
“It can’t be automated”
Slide 5
Slide 5 text
“I already test it with Cucumber”
Slide 6
Slide 6 text
“I don’t have any REAL BUSINESS LOGIC in my JavaScript”
Slide 7
Slide 7 text
“It’s too hard”
Slide 8
Slide 8 text
“It changes too often”
Slide 9
Slide 9 text
“I’m lazy”
Slide 10
Slide 10 text
“It’s not worth the effort”
Slide 11
Slide 11 text
I have [ ] more [ ] less JavaScript in my code than I used to.
Slide 12
Slide 12 text
I have [ X ] more [ ] less JavaScript in my code than I used to.
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
Rubyists need not fear
Slide 15
Slide 15 text
the authors may have seen RSpec before
Slide 16
Slide 16 text
describe RomanNumeral do it "should convert I to 1" do subject = RomanNumeral.new("I") subject.to_i.should eq(1) end end
Slide 17
Slide 17 text
describe("RomanNumeral", function() { it("returns 1 for I", function() { var subject = new RomanNumeral("I"); return expect(subject.toI()).toBe(1); }); });
Slide 18
Slide 18 text
basics
Slide 19
Slide 19 text
RSpec Jasmine describe User do describe(“User”, function() it “saves stuff” do it (“saves stuff”, function() value.should expect(value)
Slide 20
Slide 20 text
matchers
Slide 21
Slide 21 text
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
Slide 22
Slide 22 text
No content
Slide 23
Slide 23 text
No content
Slide 24
Slide 24 text
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();
Slide 25
Slide 25 text
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();
Slide 26
Slide 26 text
toBeDefined / toBeUndefined toMatch(/regex/) toThrow custom matchers as well
Slide 27
Slide 27 text
beforeEach afterEach
Slide 28
Slide 28 text
xdescribe xit
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
test doubles
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
spies
Slide 33
Slide 33 text
No content
Slide 34
Slide 34 text
No content
Slide 35
Slide 35 text
No content
Slide 36
Slide 36 text
No content
Slide 37
Slide 37 text
No content
Slide 38
Slide 38 text
No content
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
stubs
Slide 42
Slide 42 text
No content
Slide 43
Slide 43 text
jasmine-stealth
Slide 44
Slide 44 text
No content
Slide 45
Slide 45 text
fakes
Slide 46
Slide 46 text
No content
Slide 47
Slide 47 text
mocks
Slide 48
Slide 48 text
ease of use
Slide 49
Slide 49 text
No content
Slide 50
Slide 50 text
No content
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
but, semicolons are still for losers
Slide 53
Slide 53 text
describe("RomanNumeral", function() { it("returns 1 for I", function() { var subject = new RomanNumeral("I"); return expect(subject.toI()).toBe(1); }); });
Slide 54
Slide 54 text
describe "RomanNumeral", -> it "returns 1 for I", -> subject = new RomanNumeral("I") expect(subject.toI()).toBe 1
Slide 55
Slide 55 text
Great, so how do I run this stuff?
Slide 56
Slide 56 text
www.tryjasmine.com
Slide 57
Slide 57 text
No content
Slide 58
Slide 58 text
Jasmine standalone
Slide 59
Slide 59 text
https://github.com/ pivotal/jasmine/ downloads
Slide 60
Slide 60 text
No content
Slide 61
Slide 61 text
Jasmine within Rails
Slide 62
Slide 62 text
gem install jasmine
Slide 63
Slide 63 text
jasmine-headless-webkit
Slide 64
Slide 64 text
No content
Slide 65
Slide 65 text
No content
Slide 66
Slide 66 text
gem install jasmine-rails
Slide 67
Slide 67 text
Available for other enviroments as well
Slide 68
Slide 68 text
what now?
Slide 69
Slide 69 text
it’s not that hard
Slide 70
Slide 70 text
it is important
Slide 71
Slide 71 text
you have no excuses
Slide 72
Slide 72 text
Thanks! @toddkaufman @testdouble