Testing JS with Jasmine
Upcoming SlideShare
Loading in...5
×
 

Testing JS with Jasmine

on

  • 1,999 views

Jasmine itself and useful instruments

Jasmine itself and useful instruments

Statistics

Views

Total Views
1,999
Slideshare-icon Views on SlideShare
1,999
Embed Views
0

Actions

Likes
3
Downloads
34
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Testing JS with Jasmine Testing JS with Jasmine Presentation Transcript

  • Testing JS with JasmineJasmine itself and useful instruments
  • JavaScriptCoffeeScript
  • Jasmine instrumentsSuites beforeEachSpecs afterEachMatchers SpiesCustom Matchers Asynchronous specs
  • Jasmine instruments Spies spyOn(...).andCallThrough() spyOn(...).andReturn(arguments)Spying spyOn(...).andThrow(exception)Mocking spyOn(...).andCallFake(function)Faking callCount mostRecentCall.args argsForCall[i]
  • Jasmine Asynchronous specsruns(function)waits(timeout)waitsFor(function, optional message, optional timeout)
  • Jasmine minusesRuns in browser⌘+R (F5)No fixturesStatic JS vs AssetPipelineAJAX mocking isn’t friendly
  • Guard
  • GuardGuard is a command line toolto easily handle events on file modifications. gem guard-rspec gem guard-annotate gem guard-bundler gem guard-rails-assets gem guard-jasmine-headless-webkit
  • jasmine-headless-webkit
  • jasmine-headless-webkitIt integrates with Guard for a continuous testing setup.It compiles CoffeeScript, both for your tests and for your applicationlogic.It can be configured like RSpec, and its output is very similar to RSpecsoutput.It provides cleaner debugging and backtrace output than a lot of otherconsole-based test tools provide.Its fast.
  • jasmine-headless-webkitNeeds Qt (actually this is not a problem but Qt compiles a lot of time)-
  • jasmine-jquery
  • jasmine-jqueryAds JQuery specific MatchersAds FixturesAds Event Spies
  • jasmine-jquery MatcherstoBe selector toContain selectortoBeChecked toExisttoBeEmpty toHaveAttr name, valuetoBeHidden toHaveClass classNametoBeSelected toHandle eventNametoBeVisible etc...
  • jasmine-jquery Fixtures<div id="my-fixture">some complex content here</div>loadFixtures myfixture.html$(#my-fixture).myTestedPlugin()expect($(#my-fixture)).to...
  • jasmine-jquery Event SpiesspyOnEvent $(#some_element), click$(#some_element).click()expect(click).toHaveBeenTriggeredOn $#some_element
  • jasmine-ajax
  • jasmine-ajax1.Defining test responses2.Installing the mock3.Defining the response for each request4.Inspecting Ajax requests and setting expectations on them
  • Time for code
  • Linkshttps://github.com/pivotal/jasmine/wikihttp://jashkenas.github.com/coffee-script/http://johnbintz.github.com/jasmine-headless-webkit/https://github.com/velesin/jasmine-jqueryhttps://github.com/pivotal/jasmine-ajaxhttps://github.com/guard/guard/wiki/List-of-available-Guards