!SLIDE

Tea Time

A Beginner's Guide to JavaScript Testing using Jasmine

By John Bintz

!SLIDE # Automated testing is important !SLIDE # Why is it important? !SLIDE image-80-percent !SLIDE # Fortunately, we're beyond that nowadays !SLIDE even-larger ``` ruby describe MyCoolWebsite do let(:website) { described_class.new } describe '#cool_method' do subject { website.cool_method } let(:oh_yeah) { [ double_cool ] } let(:double_cool) { 'double cool' } before do website.stubs(:whoa_cool). returns(oh_yeah) end it { should == double_cool } end end ``` !SLIDE # But there's more to web apps than Ruby nowadays... !SLIDE even-larger ``` html ``` !SLIDE even-larger ``` javascript function showMyCoolTitle(title, length) { if (length == null) { length = 0; } if (length <= title.length) { document.title = title.substr(0, length); length++; setTimeout(function() { showMyCoolTitle(title, length); }, 75); } } ``` !SLIDE even-larger ``` javascript window.onload = function() { showMyCoolTitle( "My cool website! Whoaaaaa!" ); } ``` !SLIDE # jQuery !SLIDE # Backbone.js !SLIDE # Sprockets and RequireJS !SLIDE # Automated testing is important !SLIDE even-larger ``` ruby describe MyCoolWebsite do let(:website) { described_class.new } describe '#cool_method' do subject { website.cool_method } let(:oh_yeah) { [ double_cool ] } let(:double_cool) { 'double cool' } before do website.stubs(:whoa_cool). returns(oh_yeah) end it { should == double_cool } end end ``` !SLIDE even-larger ``` coffeescript describe 'MyCoolWebsiteView', -> beforeEach -> @website = new MyCoolWebsiteView() describe '#coolMethod', -> doubleCool = 'double cool' ohYeah = [ doubleCool ] beforeEach -> @website.whoaCool = -> ohYeah it 'should be double cool', -> expect(@website.coolMethod()). toEqual(doubleCool) ``` !SLIDE # Jasmine !SLIDE # BDD unit testing framework for JavaScript !SLIDE # Platform independent !SLIDE # Easily extended !SLIDE # Very easy to learn!